I’ve used this batch script to remove OneDrive from Windows 10 20H2 clients used by students. The script has been added to the end of our MDT student deployment.
@echo off
REM Prevents all commands from being displayed including ‘echo off’
set x86=”%SYSTEMROOT%\System32\OneDriveSetup.exe”
set x64=”%SYSTEMROOT%\SysWOW64\OneDriveSetup.exe”
REM Specifies environment-variables named x86 & x64.
taskkill /f /im OneDrive.exe > NUL 2>&1
REM Forcefully terminate the process using the image name ‘OneDrive.exe’.
REM ‘NUL 2>&1’ suppress outputs and pipe errors to null.
ping 127.0.0.1 -n 5 > NUL 2>&1
REM Misuse the ping command to delay commands, ‘-n 5’ specifies 5 pings. There is a 1s delay between each ping.
if exist %x64% (
%x64% /uninstall
) else (
%x86% /uninstall
)
REM Use the ‘if exist’ condition to uninstall both 32bit & 64bit versions of OneDrive.
ping 127.0.0.1 -n 10 > NUL 2>&1
REM Misuse the ping command to delay commands, ‘-n 10’ specifies 10 pings.
rd “%USERPROFILE%\OneDrive” /Q /S > NUL 2>&1
rd “C:\OneDriveTemp” /Q /S > NUL 2>&1
rd “%LOCALAPPDATA%\Microsoft\OneDrive” /Q /S > NUL 2>&1
rd “%PROGRAMDATA%\Microsoft OneDrive” /Q /S > NUL 2>&1
REM Remove OneDrive remnants. Delete directories and directory trees silently.
REG DELETE “HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}” /f > NUL 2>&1
REG DELETE “HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}” /f > NUL 2>&1
REM Remove OneDrive from File Explorer. Delete registry values without any confirmation prompt.
exit /b 0
REM Specifies to exit the current batch script. The numeric number specifies the process exit code. Exit code is required for MDT deployment to finish without errors.