Microsoft OneDrive - Remove
config/tweaks.json
642 "WPFTweaksRemoveOneDrive": {
643 "Content": "Microsoft OneDrive - Remove",
644 "Description": "Denies permission to remove OneDrive user files, then uses its own uninstaller to remove it and restores the original permission afterward.",
645 "category": "z__Advanced Tweaks - CAUTION",
646 "panel": "1",
647 "InvokeScript": [
648 "
649 # Deny permission to remove OneDrive folder
650 icacls $Env:OneDrive /deny \"Administrators:(D,DC)\"
651
652 Write-Host \"Uninstalling OneDrive...\"
653 Start-Process -FilePath (Join-Path $Env:SystemRoot \"System32\\OneDriveSetup.exe\") -ArgumentList '/uninstall' -Wait
654
655 # Some of OneDrive files use explorer, and OneDrive uses FileCoAuth
656 Write-Host \"Removing leftover OneDrive Files...\"
657
658 Stop-Process -Name FileCoAuth,Explorer
659
660 Remove-Item \"$Env:LocalAppData\\Microsoft\\OneDrive\" -Recurse -Force
661 Remove-Item \"$Env:ProgramData\\Microsoft OneDrive\" -Recurse -Force
662
663 # Grant back permission to access OneDrive folder
664 icacls $Env:OneDrive /grant \"Administrators:(D,DC)\"
665
666 if (-not (Get-ChildItem -Path $Env:OneDrive)) {
667 Remove-Item -Path $Env:OneDrive -Recurse
668 [Environment]::SetEnvironmentVariable('OneDrive', $null, 'User')
669 }
670
671 # Disable OneSyncSvc
672 Set-Service -Name OneSyncSvc -StartupType Disabled
673 "
674 ],
675 "UndoScript": [
676 "
677 Write-Host \"Installing OneDrive\"
678 winget install Microsoft.Onedrive --source winget
679
680 # Enabled OneSyncSvc
681 Set-Service -Name OneSyncSvc -StartupType Automatic
682 "
683 ],