Created
December 13, 2018 07:05
-
-
Save OSDeploy/1f073a2526f4f9dff6470b79c963ebd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# David Segura | |
# http://osdeploy.com | |
# | |
# OSBuilder Script | |
# Remove-OneDriveSetup.ps1 | |
#====================================================================================== | |
# Remove Files | |
#====================================================================================== | |
if (Test-Path "$MountDirectory\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk") { | |
Remove-Item -Path "$MountDirectory\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Force | Out-Null | |
} | |
#====================================================================================== | |
# Load Registry Hives | |
#====================================================================================== | |
$RegDefault = "$MountDirectory\Windows\System32\Config\Default" | |
if (Test-Path $RegDefault) { | |
Write-Host "Loading $RegDefault" -ForegroundColor Cyan | |
Start-Process reg -ArgumentList "load HKLM\MountDefault $RegDefault" -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
} | |
$RegDefaultUser = "$MountDirectory\Users\Default\ntuser.dat" | |
if (Test-Path $RegDefaultUser) { | |
Write-Host "Loading $RegDefaultUser" -ForegroundColor Cyan | |
Start-Process reg -ArgumentList "load HKLM\MountDefaultUser $RegDefaultUser" -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
} | |
$RegSoftware = "$MountDirectory\Windows\System32\Config\Software" | |
if (Test-Path $RegSoftware) { | |
Write-Host "Loading $RegSoftware" -ForegroundColor Cyan | |
Start-Process reg -ArgumentList "load HKLM\MountSoftware $RegSoftware" -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
} | |
$RegSystem = "$MountDirectory\Windows\System32\Config\System" | |
if (Test-Path $RegSystem) { | |
Write-Host "Loading $RegSystem" -ForegroundColor Cyan | |
Start-Process reg -ArgumentList "load HKLM\MountSystem $RegSystem" -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
} | |
#====================================================================================== | |
# Registry Commands | |
#====================================================================================== | |
$RegCommands = | |
'delete HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v OneDriveSetup /f' | |
foreach ($Command in $RegCommands) { | |
if ($Command -like "*HKCU*") { | |
$Command = $Command -replace "HKCU","HKLM\MountDefaultUser" | |
Write-Host "reg $Command" -ForegroundColor Green | |
Start-Process reg -ArgumentList $Command -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
} elseif ($Command -like "*HKLM\Software*") { | |
$Command = $Command -replace "HKLM\Software","HKLM\MountSoftware" | |
Write-Host "reg $Command" -ForegroundColor Green | |
Start-Process reg -ArgumentList $Command -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
} elseif ($Command -like "*HKLM\System*") { | |
$Command = $Command -replace "HKLM\System","HKLM\MountSystem" | |
Write-Host "reg $Command" -ForegroundColor Green | |
Start-Process reg -ArgumentList $Command -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
} | |
} | |
#====================================================================================== | |
# Unload Registry Hives | |
#====================================================================================== | |
Start-Process reg -ArgumentList "unload HKLM\MountDefault" -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
Start-Process reg -ArgumentList "unload HKLM\MountDefaultUser" -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
Start-Process reg -ArgumentList "unload HKLM\MountSoftware" -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
Start-Process reg -ArgumentList "unload HKLM\MountSystem" -Wait -WindowStyle Hidden -ErrorAction SilentlyContinue | |
#====================================================================================== | |
# Testing | |
#====================================================================================== | |
# [void](Read-Host 'Press Enter to continue') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment