Skip to content

Microsoft OneDrive - Remove

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