Powerful Code Snippets

Production-ready Ubuntu, Bash, and PowerShell 7 commands for sysadmins and developers

OneDrive Removal Suite - Production-Grade PowerShell Script

December 30, 2025 Updated May 29, 2026
powershell windows onedrive debloat removal system-administration

Overview

Production-grade PowerShell script for safely removing Microsoft OneDrive from Windows systems. Designed with safety, transparency, and user control.

Key Features

  • Safety First - Dual-confirmation system prevents accidental execution
  • Comprehensive Logging - All actions recorded for troubleshooting
  • Error Handling - Individual failures don't crash the process
  • Compatibility - PowerShell 3.0+ and Windows 7-11
  • Group Policy Support - Auto-generates remediation script for enterprise systems

System Requirements

  • OS: Windows 7, 8, 10, 11
  • PowerShell: Version 3.0 or higher
  • Permissions: Administrator (required)

What Gets Removed

Processes

OneDrive.exe
OneDriveStandaloneUpdater.exe

Folders & Registry

User profile OneDrive folder, temporary files, registry entries, and Shell integration

How to Use

# Method 1: Direct execution
.\OneDrive-Removal-Suite.ps1

# Method 2: With Bypass (if needed)
powershell -ExecutionPolicy Bypass -File ".\OneDrive-Removal-Suite.ps1"

Important Warnings

Group Policy Remediation

If your system has Group Policy controlling OneDrive:

  • Script automatically detects Group Policy settings
  • Auto-generates remediation script to remove policy constraints
  • Prevents automatic OneDrive reinstallation

Download & Verification

Complete package includes README, verification guide, and SHA256 checksums for file integrity.

Download OneDrive Removal Suite

Version History

v1.0 (December 30, 2025)

  • Full OneDrive removal functionality
  • Dual-confirmation system
  • Group Policy detection and remediation
  • Comprehensive logging
  • PowerShell 3.0+ compatibility
  • Windows 7-11 support

License

Feel free to share, modify, and distribute this script. Attribution appreciated.

Why You Might Want OneDrive Removed

OneDrive integrates deeply into Windows 10 and 11 — it hooks into File Explorer, syncs your Desktop and Documents folders, and runs background processes even when you're not actively using it. For power users, IT administrators managing fleets of PCs, or anyone who prefers a different cloud provider, removing it entirely is a reasonable choice. Common reasons include: reclaiming startup time, eliminating sync conflicts, reducing background disk I/O, and maintaining full local control over files.

The Manual Uninstall Method

Before running PowerShell, try the standard uninstall path first — Microsoft does provide one, though it's buried:

  1. Open Settings → Apps → Installed Apps
  2. Search for Microsoft OneDrive
  3. Click the three-dot menu → Uninstall

This works cleanly on Windows 11 22H2 and later. If it fails, is greyed out, or OneDrive reinstalls itself after a Windows Update, the PowerShell approach below is the reliable fallback.

Preventing OneDrive from Reinstalling

Windows Updates occasionally restore OneDrive. Block this with a Group Policy edit (works on Pro/Enterprise) or a registry key (works on all editions):

# Prevent OneDrive reinstall via registry (all Windows editions)
$regPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive"
If (!(Test-Path $regPath)) { New-Item -Path $regPath -Force }
Set-ItemProperty -Path $regPath -Name "DisableFileSyncNGSC" -Value 1 -Type DWord

# Also prevent the setup experience from auto-launching
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" `
    -Name "OneDrive" -Value "" -ErrorAction SilentlyContinue

To apply via Group Policy on Pro/Enterprise: run gpedit.msc, navigate to Computer Configuration → Administrative Templates → Windows Components → OneDrive, and enable "Prevent the usage of OneDrive for file storage".

Redirecting Shell Folders Back to Local Paths

If OneDrive had backup of Desktop, Documents, or Pictures enabled, those folders may now point to C:\Users\YourName\OneDrive\Documents instead of the local path. Fix this after removal:

# Check current shell folder paths
$shell = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
Get-ItemProperty $shell | Select-Object Desktop, Personal, "{My Pictures}"

# Reset Documents to local path
$user = $env:USERNAME
Set-ItemProperty -Path $shell -Name "Personal" -Value "C:\Users\$user\Documents"
Set-ItemProperty -Path $shell -Name "Desktop"  -Value "C:\Users\$user\Desktop"

OneDrive Alternatives Worth Considering

Removing OneDrive doesn't mean giving up cloud sync. Alternatives that integrate well without Windows-level hooks include Nextcloud (self-hosted, full control), Syncthing (peer-to-peer, no cloud middleman), Google Drive for Desktop, and Backblaze for pure backup. For business users, Tresorit and ProtonDrive offer end-to-end encryption that OneDrive doesn't provide by default.

Troubleshooting Leftover Artifacts

After uninstall, OneDrive sometimes leaves behind registry keys, scheduled tasks, or a stubborn process. Clean these manually:

# Kill any running OneDrive process
Stop-Process -Name OneDrive -Force -ErrorAction SilentlyContinue

# Remove leftover scheduled tasks
Get-ScheduledTask | Where-Object { $_.TaskName -like "*OneDrive*" } | Unregister-ScheduledTask -Confirm:$false

# Clean up residual app data folders
Remove-Item "$env:LOCALAPPDATA\Microsoft\OneDrive" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$env:PROGRAMDATA\Microsoft OneDrive" -Recurse -Force -ErrorAction SilentlyContinue

Frequently Asked Questions

Will removing OneDrive delete my files?
No — uninstalling OneDrive only removes the sync client. Files already synced to your local drive remain untouched. Files stored only in the cloud will need to be downloaded first.
Does this work on Windows 11?
Yes, the PowerShell commands above work on Windows 10 and 11. Windows 11 made the GUI uninstall easier, so try that path first.
Can I reinstall OneDrive later?
Yes — download the latest installer from microsoft.com at any time. Undo the registry policy key first if you added it.

PowerShell 7 Advanced System Administration Commands

December 17, 2025 Updated May 29, 2026
powershell windows system-admin automation scripting

PowerShell 7 Core Concepts

PowerShell 7 is cross-platform and packed with powerful cmdlets for system administration. These snippets work on Windows, Linux, and macOS.

1. System Information Gathering

Get comprehensive system information:

# Detailed system info
Get-ComputerInfo | Select-Object CsName, OsArchitecture, OsVersion, CsTotalPhysicalMemory

# CPU and memory usage
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 Name, CPU, WorkingSet

# Disk space analysis
Get-PSDrive -PSProvider FileSystem | Select-Object Name, @{N="Used(GB)";E={[math]::Round($_.Used/1GB,2)}}, @{N="Free(GB)";E={[math]::Round($_.Free/1GB,2)}}

2. Service Management

Manage Windows services with filtering and automation:

# List all running services
Get-Service | Where-Object {$_.Status -eq "Running"} | Select-Object Name, DisplayName, StartType

# Stop and disable a service
Stop-Service -Name "ServiceName" -Force
Set-Service -Name "ServiceName" -StartupType Disabled

# Restart multiple services
$services = @("Service1", "Service2", "Service3")
$services | ForEach-Object { Restart-Service -Name $_ -Force }

Network Administration

3. Advanced Network Diagnostics

PowerShell network troubleshooting commands:

# Get all network adapters with IP config
Get-NetIPAddress | Select-Object InterfaceAlias, IPAddress, PrefixLength

# Test connectivity with detailed output
Test-NetConnection -ComputerName google.com -InformationLevel Detailed

# Get active TCP connections
Get-NetTCPConnection | Where-Object {$_.State -eq "Established"} | Select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort, State

Automation Tips

  • Save frequently used scripts as .ps1 files in your scripts directory
  • Use PowerShell profiles to load custom functions on startup
  • Leverage -WhatIf parameter to test commands before execution
  • Create scheduled tasks with Register-ScheduledTask for automation
  • Use error handling with try/catch blocks in production scripts

File System Operations at Scale

PowerShell's pipeline makes bulk file operations far more powerful than anything you can do in File Explorer. Get-ChildItem, combined with Where-Object and ForEach-Object, handles thousands of files cleanly:

# Find files over 500 MB modified in the last 30 days
Get-ChildItem C:\Data -Recurse -File |
    Where-Object { $_.Length -gt 500MB -and $_.LastWriteTime -gt (Get-Date).AddDays(-30) } |
    Select-Object FullName, @{n='SizeMB';e={[math]::Round($_.Length/1MB,1)}} |
    Sort-Object SizeMB -Descending

# Bulk rename — add date prefix
Get-ChildItem C:\Reports\*.pdf | Rename-Item -NewName { "2026_$($_.Name)" }

Querying the Windows Event Log

The Windows Event Viewer GUI is slow for bulk analysis. PowerShell's Get-WinEvent is orders of magnitude faster and scriptable:

# Last 50 critical and error events from System log
Get-WinEvent -LogName System -MaxEvents 200 |
    Where-Object { $_.LevelDisplayName -in 'Critical','Error' } |
    Select-Object TimeCreated, Id, Message |
    Format-Table -AutoSize

# Failed logon attempts (Security log, Event ID 4625)
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625; StartTime=(Get-Date).AddHours(-24)} |
    Select-Object TimeCreated, @{n='User';e={$_.Properties[5].Value}},
                  @{n='IP';e={$_.Properties[19].Value}}

Local User and Group Management

Managing local accounts without leaving the terminal keeps workflows scriptable and auditable:

# List local users and whether they're enabled
Get-LocalUser | Select-Object Name, Enabled, LastLogon, PasswordLastSet

# Create a restricted service account
$pw = ConvertTo-SecureString "Str0ng!Pass" -AsPlainText -Force
New-LocalUser "svc_backup" -Password $pw -FullName "Backup Service" -Description "Runs nightly backup"
Add-LocalGroupMember -Group "Backup Operators" -Member "svc_backup"

# Disable a stale account
Disable-LocalUser -Name "old.employee"

Scheduled Tasks via PowerShell

The ScheduledTasks module provides full control over the Task Scheduler from the command line — no GUI needed:

# List all tasks and their last run result
Get-ScheduledTask | Get-ScheduledTaskInfo |
    Select-Object TaskName, LastRunTime, LastTaskResult |
    Where-Object { $_.LastTaskResult -ne 0 }   # non-zero = error

# Create a daily maintenance task
$action  = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument "-File C:\Scripts\cleanup.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At 2am
$settings = New-ScheduledTaskSettingsSet -RunOnlyIfIdle:$false -StartWhenAvailable
Register-ScheduledTask "DailyCleanup" -Action $action -Trigger $trigger -Settings $settings -RunLevel Highest

Registry Operations

PowerShell treats the registry as a drive — you can navigate and modify it with the same verbs used for files:

# Read a value
Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion" -Name ProgramFilesDir

# Set a DWORD to disable a feature
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" `
    -Name "HideFileExt" -Value 0 -Type DWord

# Export a key subtree for backup before editing
reg export "HKCU\Software\MyApp" C:\Backups\myapp_reg_$(Get-Date -f yyyyMMdd).reg

Always export the key before modifying it in production. Registry mistakes can prevent Windows from booting — treat it with the same respect you would a production database.