What It Does
The script runs from SYSTEM and starts the steps in the session of the user signed in at the console. It finds OneDrive.exe in the user's own Microsoft OneDrive folder under LocalAppData, then in Program Files, then in Program Files (x86). It runs OneDrive.exe /reset, which stops OneDrive and clears its sync settings and cache, waits up to RestartWaitSeconds for OneDrive to start again by itself, starts it again with OneDrive.exe /background if it did not, and checks that OneDrive is running for that user.
After a reset OneDrive scans and re-syncs everything. On a large library that can take hours and use bandwidth. No file is deleted from the PC or from the cloud, but OneDrive may forget folder choices from selective sync, and the user may have to confirm their account. Tell the user first.
It never touches the files in the OneDrive folders, other users, or a user who is not signed in. Nobody signed in is SKIPPED, and OneDrive not installed for that user is SKIPPED. Running it twice resets twice.
Before You Run It
- Tell the user first. OneDrive re-syncs everything, which can take hours on a large library.
- Try it out of working hours on a PC with a slow connection or a very large library.
- Run it while the user is signed in. With nobody signed in it is skipped.
- Run it with DryRun=true first. It says which OneDrive.exe it would reset and for whom.
When to Reset OneDrive
Consider a reset when sync is stuck across multiple folders on one Windows PC, the same work account can open its files in the browser, and resuming sync and quitting and reopening OneDrive did not help.
Check the sync error first. If one file is blocked, inspect its name, path and permissions. If OneDrive reports full storage, fix the quota problem. If coworkers or the web app are affected, check Microsoft 365 service health, access and account status before resetting a client. Before a reset, record the folders selected for sync and make a separate local copy of any critical edits that have yet to reach the web.
Worked Ticket: Sync Stalled on One PC
Fictional ticket HD-2512. On WIN-32, Alex can open the work library online, but the local sync queue stays stuck across several folders after reopening the client. With EXAMPLE\alex signed in at the console, run from the Windows RMM as SYSTEM with DryRun=true, OutputFormat=Text and RestartWaitSeconds=60. Leave ExportPath and ResultField unset.
In this example the detection line identifies EXAMPLE\alex and finds OneDrive.exe under that user’s LocalAppData. Both rows show Would change: Run OneDrive.exe /reset and wait for OneDrive to restart, then Start OneDrive with /background if it did not restart by itself. The final line is:
RESULT: DRYRUN | Dry run, nothing changed. Would have: Reset OneDrive for EXAMPLE\alex; it is started again if it does not restart. It re-syncs; no files are deleted.
If the account differs from the ticket, hold. If the result is SKIPPED, check that the intended user is signed in at the console and the Windows sync client is installed. With the account confirmed, agree on a time for the re-sync and use DryRun=false once. Microsoft says a reset disconnects existing sync connections, including work and personal connections when both are set up. Restore selective folder choices once sync completes.
Verify the Fix
CHANGED confirms a OneDrive process for the user. Open the blue cloud icon, confirm the correct work account and library, and wait for the sync errors and queue to clear. Use a harmless test file in the affected folder and confirm it appears in OneDrive on the web. If sync stays stalled, capture the error code, affected path and timestamp and investigate that error before trying another reset.
Microsoft References
What do the OneDrive error codes mean?
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
- What it changes: Runs OneDrive.exe /reset for the signed-in user (OneDrive stops, clears its sync state and re-syncs); starts OneDrive again if it did not restart.
- Restart: It never restarts the machine.
- Typical run: 1 to 3 minutes.
- Example answer: "Reset OneDrive for PC01\jsmith; it restarted on its own and is running. It re-syncs; no files are deleted."
- Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- RestartWaitSeconds: How long to wait for OneDrive to restart by itself after the reset before starting it with /background. Whole number, 5 to 300. Default 60.
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.