You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.3 KiB
55 lines
2.3 KiB
# Description:
|
|
# This script will remove and disable OneDrive integration.
|
|
|
|
Import-Module -DisableNameChecking $PSScriptRoot\..\lib\take-own.psm1
|
|
|
|
echo "Kill OneDrive process"
|
|
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 "Removing OneDrive leftovers"
|
|
rm -Recurse -Force -ErrorAction SilentlyContinue "$env:localappdata\Microsoft\OneDrive"
|
|
rm -Recurse -Force -ErrorAction SilentlyContinue "$env:programdata\Microsoft OneDrive"
|
|
rm -Recurse -Force -ErrorAction SilentlyContinue "$env:userprofile\OneDrive"
|
|
rm -Recurse -Force -ErrorAction SilentlyContinue "C:\OneDriveTemp"
|
|
|
|
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 "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" 0
|
|
mkdir -Force "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}"
|
|
sp "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" "System.IsPinnedToNameSpaceTree" 0
|
|
Remove-PSDrive "HKCR"
|
|
|
|
# Thank you Matthew Israelsson
|
|
echo "Removing run hook for new users"
|
|
reg load "hku\Default" "C:\Users\Default\NTUSER.DAT"
|
|
reg delete "HKEY_USERS\Default\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "OneDriveSetup" /f
|
|
reg unload "hku\Default"
|
|
|
|
echo "Removing startmenu entry"
|
|
rm -Force -ErrorAction SilentlyContinue "$env:userprofile\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"
|
|
|
|
echo "Restarting explorer"
|
|
start "explorer.exe"
|
|
|
|
echo "Waiting for explorer to complete loading"
|
|
sleep 10
|
|
|
|
echo "Removing additional OneDrive leftovers"
|
|
foreach ($item in (ls "$env:WinDir\WinSxS\*onedrive*")) {
|
|
Takeown-Folder $item.FullName
|
|
rm -Recurse -Force $item.FullName
|
|
}
|
|
|