Last active
August 1, 2023 12:38
-
-
Save grenade/c20050d28a6ab456d9b304ab30d320a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# uninstall onedrive | |
Start-Process -FilePath 'c:\Windows\SysWOW64\OneDriveSetup.exe' -ArgumentList @('/uninstall') -NoNewWindow -Wait | |
# disable onedrive file sync | |
New-Item -ItemType Directory -Force -Path 'HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive' | |
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive' -Name 'DisableFileSyncNGSC' -Value 1 | |
# remove onedrive from explorer menu | |
New-PSDrive -Name 'HKCR' -PSProvider 'Registry' -Root 'HKEY_CLASSES_ROOT' | |
Set-ItemProperty -Path 'HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}' -Name 'System.IsPinnedToNameSpaceTree' 0 | |
Set-ItemProperty -Path 'HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}' -Name 'System.IsPinnedToNameSpaceTree' 0 | |
Remove-PSDrive -Name 'HKCR' | |
# delete onedrive folders | |
$oneDrivePaths = @(@((Get-ChildItem -Path ('{0}\WinSxS' -f $env:WinDir) -Filter '*onedrive*') | % { $_.FullName }) + @( | |
('{0}\Microsoft\OneDrive' -f $env:LocalAppData), | |
('{0}\Microsoft OneDrive' -f $env:ProgramData), | |
('{0}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk' -f $env:UserProfile) | |
) | ? { Test-Path -Path $_ -ErrorAction SilentlyContinue }) | |
foreach ($path in ($oneDrivePaths)) { | |
& takeown.exe @('/a', '/f', $path, '/r', '/d', 'Y') | |
& icacls.exe @($path, '/grant', 'Administrators:F', '/t') | |
Remove-Item -Path $path -Force -Recurse | |
} | |
# prevent onedrive setup from running on first login of new user | |
& reg.exe @('load', 'HKU\Default', 'C:\Users\Default\NTUSER.DAT') | |
& reg.exe @('delete', 'HKEY_USERS\Default\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', '/v', 'OneDriveSetup', '/f') | |
& reg.exe @('unload', 'HKU\Default') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment