Forum Discussion
OlivierKipLucrasoft
Feb 12, 2025Copper Contributor
Automate Powershell Force OneDrive to Re Sync if there is a Sync Error noted
we use an RMM to automate powershell scripts to workdevices to monitor them.
We get a lot of "OneDrive for Business, error with syncing" alerts. What I always see is that if OneDrive is restarted (manually) the sync is done again and the error is solved.
Do people have a powershell script to "re sync", a script that we can initialize when an alert like this is coming up. So we don't have to manually restart or reïnstall onedrive to solve it
- vimal_raj1984hotmailCopper Contributor
try {
# Stop OneDrive process
Get-Process OneDrive -ErrorAction SilentlyContinue | Stop-Process -Force# Wait for the process to stop completely
Start-Sleep -Seconds 5# Start OneDrive again
Start-Process -FilePath "$env:LOCALAPPDATA\Microsoft\OneDrive\OneDrive.exe"# Optional: Wait and check if OneDrive is running
Start-Sleep -Seconds 10
if (Get-Process OneDrive -ErrorAction SilentlyContinue) {
Write-Output "OneDrive restarted successfully."
} else {
Write-Output "Failed to restart OneDrive."
}} catch {
Write-Output "An error occurred: $_"
}