Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save realslacker/cdc5a9fd5f8d49133d7e13130147b477 to your computer and use it in GitHub Desktop.
Save realslacker/cdc5a9fd5f8d49133d7e13130147b477 to your computer and use it in GitHub Desktop.
Removes Provisioned Appx Packages from a WIM file to allow Windows to be deployed without the provisioned apps pre-installed.
<#
.SYNOPSIS
Removing Built-in apps from Windows 10 / Windows 8.1 / Windows 8
.DESCRIPTION
Removing Built-in apps from Windows 10 / Windows 8.1 / Windows 8
.PARAMETER Path
The path to the WIM image file (typically install.wim)
.PARAMETER AppxPackages
An array of packages to remove (optional)
.PARAMETER Verify
Prompt for each Appx package before removal
.PARAMETER PassThru
.EXAMPLE
.\Remove-AppxProvisionedPackagesFromWim.ps1 -Path C:\Install.wim -AppxPackages
.EXAMPLE
.\Remove-AppxProvisionedPackagesFromWim.ps1 -Path C:\Install.wim -Verify
#>
[CmdletBinding(SupportsShouldProcess=$true)]
param (
[Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true)]
[string[]]
$Path,
[Parameter(Mandatory=$false, Position=2)]
[string[]]
$AppxPackages=@(),
[Parameter(Mandatory=$false)]
[int]
$Index=1,
[switch]
$Verify,
[switch]
$PassThru
)
begin {
# packages that should never be removed
$MandatoryAppxPackages = @(
'Microsoft.DesktopAppInstaller'
'Microsoft.MicrosoftStickyNotes'
#'Microsoft.MSPaint'
#'Microsoft.Office.OneNote'
'Microsoft.People'
'Microsoft.StorePurchaseApp'
'Microsoft.Wallet'
'Microsoft.Windows.Photos'
#'Microsoft.WindowsAlarms'
'Microsoft.WindowsCalculator'
#'Microsoft.WindowsCamera'
#'Microsoft.WindowsSoundRecorder'
'Microsoft.WindowsStore'
)
$StartDate = Get-Date
$TempDirectory = New-Item -Path "$env:TEMP\$($StartDate.ToString('yyyyMMddHHmmss'))" `
-ItemType Directory
Write-Verbose "Start Time: $StartDate"
Write-Verbose "Temporary Directory: $TempDirectory"
}
process {
foreach ( $Item in $Path ) {
$Item = Get-Item -Path $Item -ErrorAction Stop
Write-Host "Removing provisioned Appx Packages in '$($Item.FullName)'..." -ForegroundColor Yellow
Write-Host "Mounting Windows Image"
Mount-WindowsImage -Path $TempDirectory `
-ImagePath $Item `
-Index $Index
$AppxPackages = Get-AppxProvisionedPackage -Path $TempDirectory | Where-Object {
if ( $MandatoryAppxPackages -notcontains $_.DisplayName ) { $true }
else { $false }
} | Where-Object {
if ( $AppxPackages.Count -eq 0 ) { $true }
elseif ( $AppxPackages -contains $_.DisplayName ) { $true }
else { $false }
} | Where-Object {
if( $Verify.IsPresent ) {
if ( ( Read-Host "Remove '$($_.DisplayName)'? [y/N]" ).ToLower() -eq 'y' ) { $true }
else { $false }
}
else { $true }
}
Write-Host "Removing Built-in apps..."
$AppxPackages | Remove-AppxProvisionedPackage -Path $TempDirectory
Write-Host "Dismounting Windows Image"
Dismount-WindowsImage -Path $TempDirectory `
-Save `
-CheckIntegrity
if ( $PassThru.IsPresent ) {
Get-Item -Path $Item
}
}
}
end {
Write-Host "Cleaning Up Environment"
$TempDirectory | Remove-Item -Force `
-Confirm:$false
Write-Verbose "End Time: $((Get-Date).ToString())"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment