Skip to content

onedrive_remove_complete.ps1

Corey Watson edited this page Dec 24, 2025 · 2 revisions

onedrive_remove_complete.ps1

Performs a complete, multi-path uninstallation of Microsoft OneDrive with permanent startup suppression.

Overview

This script stops running processes, executes the official Microsoft uninstall utility against all known install paths (system and Office), removes scheduled tasks, and applies registry policies to prevent reinstallation.

Purpose

Performs a complete, multi-path uninstallation of Microsoft OneDrive with permanent startup suppression. Stops running processes, executes the official Microsoft uninstall utility against all known install paths (system and Office), removes scheduled tasks, and applies registry policies to prevent reinstallation.

Prerequisites

  • PowerShell 5.1 or later
  • Administrator privileges required
  • No network requirements (local operations only)

Configuration

Required Inputs

  • No runtime parameters required
  • All operations use hardcoded paths and registry locations

Settings

  • OneDrive Setup Paths: System32, SysWOW64, Office x86, Office x64
  • Registry GPO Path: HKLM:\Software\Policies\Microsoft\Windows\OneDrive
  • Registry Explorer Path: HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer
  • Registry Run Key: HKCU:\Software\Microsoft\Windows\CurrentVersion\Run

Data Sources & Priority

  1. Hardcoded OneDriveSetup.exe paths (system and Office locations)
  2. Registry keys for GPO, Explorer, and Run persistence
  3. Task Scheduler for OneDrive scheduled tasks
  4. WMI/CIM for system diagnostics

Behavior

  1. Validates administrative privileges
  2. Stops all running OneDrive processes
  3. Executes OneDriveSetup.exe /uninstall for each found path
  4. Removes all OneDrive scheduled tasks
  5. Sets HKLM GPO DisableFileSyncNGSC=1 to prevent startup for all users
  6. Removes HKCU Run key OneDrive entry
  7. Sets Explorer policy to hide OneDrive from navigation pane
  8. Reports completion status with reboot recommendation

Security Notes

  • No secrets (API keys, passwords) are used or logged
  • All actions confined to local files, registry, and task scheduler
  • Registry modifications use Group Policy paths for proper enforcement

Exit Codes

  • 0 : Success - all cleanup steps completed
  • 1 : Failure - critical error (likely permission-related)

Example Output

[ INPUT VALIDATION ]
--------------------------------------------------------------
Computer Name    : WKSTN-FIN-01
Username         : SYSTEM
Admin Privileges : Confirmed
Paths to Check   : 4

[ STOP PROCESSES ]
--------------------------------------------------------------
Stopping OneDrive processes...
OneDrive processes terminated

[ UNINSTALL ONEDRIVE ]
--------------------------------------------------------------
Checking path   : C:\Windows\SysWOW64\OneDriveSetup.exe
Status          : Found - executing uninstall
Result          : Uninstall command completed

Checking path   : C:\Windows\System32\OneDriveSetup.exe
Status          : Not found - skipping

Checking path   : C:\Program Files\Microsoft Office\root\...
Status          : Not found - skipping

Checking path   : C:\Program Files (x86)\Microsoft Office\root\...
Status          : Not found - skipping

Uninstallers Run : 1

[ REMOVE SCHEDULED TASKS ]
--------------------------------------------------------------
Removing OneDrive scheduled tasks...
Scheduled tasks removed

[ REGISTRY CLEANUP ]
--------------------------------------------------------------
Setting HKLM GPO DisableFileSyncNGSC = 1
HKLM GPO policy applied

Removing HKCU Run key OneDrive entry
HKCU Run key cleaned

Setting Explorer DisableOneDriveFileSync = 1
Explorer policy applied

[ FINAL STATUS ]
--------------------------------------------------------------
Result           : SUCCESS
Uninstallers Run : 1
OneDrive removal complete - reboot recommended for full cleanup

[ SCRIPT COMPLETED ]
--------------------------------------------------------------

Version History

  • 2025-11-29 v1.1.0 - Refactored to Limehawk Style A with improved validation, cleaner section organization, and enhanced error handling.
  • 2025-09-19 v1.0.0 - Initial version for complete multi-path OneDrive uninstall.

Links

Clone this wiki locally