Skip to content

Remove OneDrive

config/tweaks.json
1481  "WPFTweaksRemoveOneDrive": {
1482    "Content": "Remove OneDrive",
1483    "Description": "Denies permission to remove OneDrive user files, then uses its own uninstaller to remove it and restores the original permission afterward.",
1484    "category": "z__Advanced Tweaks - CAUTION",
1485    "panel": "1",
1486    "InvokeScript": [
1487      "
1488      # Deny permission to remove OneDrive folder
1489      icacls $Env:OneDrive /deny \"Administrators:(D,DC)\"
1490
1491      Write-Host \"Uninstalling OneDrive...\"
1492      Start-Process 'C:\\Windows\\System32\\OneDriveSetup.exe' -ArgumentList '/uninstall' -Wait
1493
1494      # Some of OneDrive files use explorer, and OneDrive uses FileCoAuth
1495      Write-Host \"Removing leftover OneDrive Files...\"
1496      Stop-Process -Name FileCoAuth,Explorer
1497      Remove-Item \"$Env:LocalAppData\\Microsoft\\OneDrive\" -Recurse -Force
1498      Remove-Item \"C:\\ProgramData\\Microsoft OneDrive\" -Recurse -Force
1499
1500      # Grant back permission to access OneDrive folder
1501      icacls $Env:OneDrive /grant \"Administrators:(D,DC)\"
1502
1503      # Disable OneSyncSvc
1504      Set-Service -Name OneSyncSvc -StartupType Disabled
1505      "
1506    ],
1507    "UndoScript": [
1508      "
1509      Write-Host \"Installing OneDrive\"
1510      winget install Microsoft.Onedrive --source winget
1511
1512      # Enabled OneSyncSvc
1513      Set-Service -Name OneSyncSvc -StartupType Automatic
1514      "
1515    ],