Check to See if Onedrive is running and or Signed in

Onedrive sometime stops working so I would like it to auto heal

Customer emails saying one drive is not working , I just say reboot

But you can fix it by starting Onedrive again however I have not been successful in creating a script or using Syncros tools.

I have discussed this abit on the facebook group but no real answers


Here ya go. I just wrote this for you and in testing it works perfectly. Mind you, this isn’t gonna work on old PowerShell lol. It can be written to work on older, but I didn’t bother.

if (!(Get-InstalledModule | Where-Object { $_.Name -eq "RunAsUser" })) {
    Write-Host "Not Installed. Installing"
    Install-Module RunAsUser -Force

$OneDrive = Get-Process OneDrive -ErrorAction "SilentlyContinue"

if ($OneDrive){
    Stop-Process $OneDrive -Force
    Start-Sleep 5

$ScriptBlock = {
    $TaskName = "Start OneDrive"
    $Action = New-ScheduledTaskAction -Execute "%localappdata%\Microsoft\OneDrive\OneDrive.exe"
    $TimeOut = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Hours 1)
    $Description = "Manual start of OneDrive after a force close"

    if (!(Get-ScheduledTask -TaskName $TaskName)) {
        Register-ScheduledTask -Action $Action -TaskName $TaskName -Settings $TimeOut -Description $Description

    Start-ScheduledTask -TaskName $TaskName

Invoke-ASCurrentUser -ScriptBlock $ScriptBlock

So what this does for you is checks if the PowerShell module RunAsUser is installed and if not, installs it. Then if OneDrive is running, kills it. Finally, under the logged in user, it creates a scheduled task and then executes the scheduled task which opens OneDrive.

The reason I had to do it via scheduled task versus just calling it directly, even under the RunAsUser, is because Syncro launches the commands via admin rights, and OneDrive will display an error to the user stating OneDrive can’t be run with full admin rights.

Do you know if there is any way to monitor it OneDrive is health?

Something like this?

OneDrive Staus via PowerShell

Also this, but I have no idea how well it works.

Monitoring OneDrive

1 Like

Cyberdrain already have a script.

1 Like