Last active
December 30, 2020 06:25
-
-
Save Jawabiscuit/74f22316273a04cd38cbbac0509e3d20 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<# | |
.Description | |
Remove all non-whitelisted apps that come installed in Windows 10 by default. | |
Warning: Test first, and only run on a fresh install otherwise some changes may be irreversible. | |
Meant for developers that want a lean system to work with or test on. | |
.Example | |
1) Download this gist | |
2) Open Powershell as Administrator | |
3) `Set-ExecutionPolicy AllSigned -Force` to enable executing scripts | |
4) Set `$Path = <path-to-downloaded-script>` in powershell | |
5) `iex ((Get-Content $Path) -join [environment]::newline)` | |
#> | |
$packages = Get-AppxProvisionedPackage -Online | Select Packagename | |
$whitelist = @( | |
"*MicrosoftEdge*", "*WindowsCalculator*", "*MSPaint*", | |
"*WindowsStore*", # Cannot re-install | |
"*Microsoft.VCLibs.*" | |
) | |
foreach ($app in $packages) { | |
$matched = $false | |
foreach ($w in $whitelist) { | |
if ($app.packagename -like $w) { | |
$matched = $true | |
break | |
} | |
} | |
if ($matched -eq $false) { | |
write-host "Uninstalling" $app.packagename | |
$tries = 0 | |
do { | |
Get-AppxPackage -Name $app.packagename -AllUsers | | |
Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue | |
Get-AppxProvisionedPackage -Online | | |
where {$_.packagename -EQ $app.packagename} | | |
Remove-AppxProvisionedPackage -AllUsers -Online -ErrorAction SilentlyContinue | |
$tries++ | |
} while ((Get-AppxProvisionedPackage -Online | Select Packagename) -match $app.packagename -or $tries -ge 2) | |
if ((Get-AppxProvisionedPackage -Online | Select Packagename) -match $app.packagename) { | |
write-host $app.packagename "failed to uninstall after $tries tries" | |
} else { | |
write-host $app.packagename "successfully uninstalled after $tries tries" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment