Last active
August 31, 2023 06:32
-
-
Save zoeeechu/038e0c82550ce2a79e4d63aef11d5326 to your computer and use it in GitHub Desktop.
Remove Microsoft OneDrive 2023 - [edit]: future proofed
This file contains 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
#Remove OneDrive | |
# zoe -2023 | |
function start-script { | |
try { | |
TASKKILL /F /IM OneDrive.exe | |
#Remove Reg Keys | |
REG Delete "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f | |
REG Delete "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f | |
REG ADD "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /v System.IsPinnedToNameSpaceTree /d "0" /t REG_DWORD /f | |
$p = 'Program Files' | |
$o = 'Microsoft OneDrive' | |
$pathsToCheck = @( | |
"C:\Users\$env:username\AppData\Local\Microsoft\OneDrive\", | |
"C:\${p}\${o}\" | |
) | |
foreach ($path in $pathsToCheck) { | |
$resolvedPath = [System.IO.Path]::GetFullPath($path) | |
if (Test-Path -Path $resolvedPath) { | |
$folders = Get-ChildItem -Path $resolvedPath -Directory | |
foreach ($folder in $folders) { | |
if ($folder.Name -match "^\d") { | |
$command = Join-Path -Path $resolvedPath -ChildPath "${folder}\OneDriveSetup.exe" | |
$arg = "/Uninstall" | |
Start-Process -FilePath $command -ArgumentList $arg -Wait | |
# Invoke-Expression "`"${command}`"" # Enclose the command in double quotes | |
} | |
} | |
} | |
else { | |
Write-Host "OneDrive path '$resolvedPath' not found." | |
} | |
} | |
} | |
catch { | |
Write-Error $_.Exception.ToString() | |
Read-Host -Prompt "Press enter.." | |
} | |
} | |
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | |
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs | |
} | |
else { | |
start-script | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment