Uninstall OneDrive per user package
I know that PDQ has a package for uninstalling some programs such as Google Chrome that were installed on a per user basis, using Powershell. I'm just curious if anyone has something similar for uninstalling all instances of Microsoft OneDrive on a machine? I can do a per user uninstall if the specific user is logged in, but I'm looking for something to capture and uninstall for all users, current and past, on the machine. Can anyone offer some help? Thanks in advance.
-
This works for me, although most stations it throws an error on the first line that the Process wasn't found, but this has removed it for any local Windows accounts that have previously logged on, or for a new user logging on.
#Import-Module -DisableNameChecking $PSScriptRoot\..\lib\force-mkdir.psm1#Import-Module -DisableNameChecking $PSScriptRoot\..\lib\take-own.psm1
echo "73 OneDrive process and explorer"taskkill.exe /F /IM "OneDrive.exe"#taskkill.exe /F /IM "explorer.exe"
echo "Remove OneDrive"if (Test-Path "$env:systemroot\System32\OneDriveSetup.exe") {& "$env:systemroot\System32\OneDriveSetup.exe" /uninstall}if (Test-Path "$env:systemroot\SysWOW64\OneDriveSetup.exe") {& "$env:systemroot\SysWOW64\OneDriveSetup.exe" /uninstall}
echo "Disable OneDrive via Group Policies"mkdir -force "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive"sp "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive" "DisableFileSyncNGSC" 1
echo "Removing OneDrive leftovers trash"rm -Recurse -Force -ErrorAction SilentlyContinue "$env:localappdata\Microsoft\OneDrive"rm -Recurse -Force -ErrorAction SilentlyContinue "$env:programdata\Microsoft OneDrive"rm -Recurse -Force -ErrorAction SilentlyContinue "C:\OneDriveTemp"
echo "Remove Onedrive from explorer sidebar"New-PSDrive -PSProvider "Registry" -Root "HKEY_CLASSES_ROOT" -Name "HKCR"mkdir -Force "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}"sp "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" "System.IsPinnedToNameSpaceTree" 0mkdir -Force "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}"sp "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" "System.IsPinnedToNameSpaceTree" 0Remove-PSDrive "HKCR"
echo "Removing run option for new users"reg load "hku\Default" "C:\Users\Default\NTUSER.DAT"reg delete "HKEY_USERS\Default\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "OneDriveSetup" /freg unload "hku\Default"
echo "Removing startmenu junk entry"rm -Force -ErrorAction SilentlyContinue "$env:userprofile\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"
#echo "Restarting explorer..."#start-process "explorer.exe"
echo "Wait for EX reload.."sleep 15
echo "Removing additional OneDrive leftovers"foreach ($item in (ls "$env:WinDir\WinSxS\*onedrive*")) {Takeown $item.FullNamerm -Recurse -Force $item.FullName}However, and I may be preaching to the choir, check your Windows Updates so they don't re-enable it, as well as when/if you do a Feature Update (ex. 1903 to 1909/2004), it will enable almost all disabled Windows built-in applications.
Please sign in to leave a comment.
Comments
8 comments