Skip to content

Instantly share code, notes, and snippets.

@neil-bh
Last active May 24, 2022 18:21
Show Gist options
  • Save neil-bh/dae414d721560d3fec8b1c652436709c to your computer and use it in GitHub Desktop.
Save neil-bh/dae414d721560d3fec8b1c652436709c to your computer and use it in GitHub Desktop.
Script to Remove Apps for Windows 10 (with multiple version support). Script updated to prevent apps returning after being removed on Pre-1803 releases of Windows 10
# Original Script by: Jörgen Nilsson
# Blog post: https://ccmexec.com/2019/04/updated-removeapps-script-for-windows-10-1903/
# Updated by: Neil Bourne-Harris (02/05/2019)
# Changelog: Added condition to prevent apps from returning by adding the apps respective deprovisioning key
# to the registry (not required for 1803 and above).
# Ref: https://docs.microsoft.com/en-us/windows/application-management/remove-provisioned-apps-during-update
$Buildnr = (Get-CimInstance Win32_Operatingsystem).BuildNumber
$Applist = Get-Content "$($PSScriptRoot)\apps$($Buildnr).txt"
$Capabilities = Get-Content "$($PSScriptRoot)\Capabilities$($Buildnr).txt"
$Logfile = "$env:SystemRoot\Temp\RemoveApps_$($Buildnr).log"
Set-Content -Path $Logfile -Value "Remove builtin apps based on $applist"
# Prevent apps from returning by adding the apps respective deprovisioning key to the registry (not required for 1803 and above)
# Ref: https://docs.microsoft.com/en-us/windows/application-management/remove-provisioned-apps-during-update
if ($Buildnr -le 16299) {
$DeprovisionedRootKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Deprovisioned"
If (!(Test-Path "$DeprovisionedRootKey")) { New-Item -Path "$DeprovisionedRootKey" | Out-Null }
}
ForEach ($App in $Applist) {
$App = $App.TrimEnd()
$PackageFullName = (Get-AppxPackage $App).PackageFullName
$ProPackageFullName = (Get-AppxProvisionedPackage -online | where {$_.Displayname -eq $App}).PackageName
$PackageFamilyName = (Get-AppxPackage | where {$_.Name -eq $App }).PackageFamilyName
if ($Buildnr -le 16299) {
if ($PackageFamilyName) {
if (!(Test-Path "$DeprovisionedRootKey\$PackageFamilyName")) {
"`r`nAdding deprovisioned package name to registry: $App" | Out-File -FilePath $Logfile -Append -Encoding ascii
New-Item -Path "$DeprovisionedRootKey\$PackageFamilyName" | Out-Null
}
}
}
if ($PackageFullName) {
"`r`nRemoving Package: $App" | Out-File -FilePath $Logfile -Append -Encoding ascii
start-sleep -Seconds 5
remove-AppxPackage -package $PackageFullName | Out-File -FilePath $Logfile -Append -Encoding ascii
}
else {
"Unable to find package: $App" | Out-File -FilePath $Logfile -Append -Encoding ascii
}
if ($ProPackageFullName) {
"`r`nRemoving Provisioned Package: $ProPackageFullName" | Out-File -FilePath $Logfile -Append -Encoding ascii
start-sleep -Seconds 5
Remove-AppxProvisionedPackage -online -packagename $ProPackageFullName | Out-File -FilePath $Logfile -Append -Encoding ascii
}
else {
"Unable to find provisioned package: $App"| Out-File -FilePath $Logfile -Append -Encoding ascii
}
}
ForEach ($Capability in $Capabilities) {
"`r`nRemoving capability: $Capability".Replace(" ", " ") | Out-File -FilePath $Logfile -Append
Remove-WindowsCapability -online -name $Capability | Out-File -FilePath $Logfile -Append -Encoding ascii
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment