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 (m...
Feb 16, 2025
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: $_"
}