-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3 Remove OneDrive Silently.ps1
38 lines (32 loc) · 1.46 KB
/
3 Remove OneDrive Silently.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Check OS architecture and set OneDrive setup path accordingly
if ([Environment]::Is64BitOperatingSystem) {
$OneDriveSetupPath = "$env:SYSTEMROOT\SysWOW64\OneDriveSetup.exe"
} else {
$OneDriveSetupPath = "$env:SYSTEMROOT\System32\OneDriveSetup.exe"
}
# Uninstall OneDrive silently
if (Test-Path $OneDriveSetupPath) {
Start-Process $OneDriveSetupPath -ArgumentList "/uninstall" -NoNewWindow -Wait
Write-Host "OneDrive has been uninstalled."
} else {
Write-Host "OneDrive setup not found."
}
# Remove residual OneDrive directories
$OneDriveFolders = @(
"$env:UserProfile\OneDrive",
"$env:LOCALAPPDATA\Microsoft\OneDrive",
"$env:ProgramData\Microsoft OneDrive"
)
foreach ($folder in $OneDriveFolders) {
if (Test-Path $folder) {
Remove-Item $folder -Force -Recurse -ErrorAction SilentlyContinue
Write-Host "Removed residual folder: $folder"
}
}
# Prevent OneDrive from being installed for new users (Optional)
# This step involves setting a Group Policy or a registry key. Uncomment the lines below to apply the registry edit.
# Note: This action is more permanent and should be used with understanding of the implications.
# Set registry key to prevent OneDrive setup for new users
# New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableFileSyncNGSC" -Value 1 -PropertyType DWORD -Force
# Write-Host "OneDrive setup for new users has been disabled."
Write-Host "OneDrive removal process completed."