Script to resync Onedrive - Reopening of Onedrive fails

I am attempting to create a script (within Procedures) that will trigger a resync for Onedrive, then reopen Onedrive on the client (I plan to schedule this a couple times a week). I believe I have added the appropriate commands to accomplish, but am getting an error about Onedrive not allowing the Administrator to open OneDrive. The script seems to run fine, closes Onedrive, then attempts to reopen Onedrive but Windows throws an error:

OneDrive can’t be run using full administrator rights. Please restart Onedrive without administrator rights.

  • When running the script I am selecting run As LoggedInUser (Which is in the administrators group if that matters) rather than Run as LocalSystemUser.

Below is the script bold where the changes were made tot he default:

#To define a particular parameter, replace the ‘parameterName’ inside itsm.getParameter(‘parameterName’) with that parameter’s name
command=r’%localappdata%\Microsoft\OneDrive\onedrive.exe /reset & %localappdata%\Microsoft\OneDrive\onedrive.exe#Please edit your command here.

import ctypes
from subprocess import PIPE, Popen
def ecmd(command):
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirect ion
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirecti on
def enter(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def exit(self, type, value, traceback):
if self.success:

with disable_file_system_redirection():
obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
out, err = obj.communicate()
if ret==0:
if out:
return out.strip()
return ret
if err:
return err.strip()
return ret
print ecmd(command)

Any help would be appreciated.



I will keep an eye on this post, I’d love to see a monitor for onedrive and if not running then auto run the start up for it.
I have most clients on 365 and by far the most grief for end users is the onedrive not running issue with local sync of sharepoint/teams, simply restarting fixes 99%.
Some users do not notice the icon missing or for what ever reason every now and again the service is disabled in start up.


Tried to setup a simple monitor on Mac that monitors the OneDrive Service and restart OneDrive with a Procedure as an auto remediation.

This seems to bee working but u have to disable notification / alerts because when shutdown the MAC, OneDrive will be shutdown by the system and this wil launch the StartOneDrive Procedure on every shutdown.

That being said, this way its nearly impossible to use Monitors on other services because they always shutdown before the Communication Client.

I think we all want a OneDrive State Monitor to see it the damn thing sync well or not or needs attention