Public/Remove-specAppxProvisionedPackage.ps1
function Remove-specAppxProvisionedPackage { <# .SYNOPSIS Remove AppX provisioned packages from the device. .DESCRIPTION This function removes AppX provisioned packages from the device. It reads the list of packages to remove from the Azure table and removes them if found. .PARAMETER RemoveList The list of AppX provisioned packages to remove. .EXAMPLE Remove-specAppxProvisionedPackage -RemoveList $appxRemovalList $appxRemovalList is an array of AppX provisioned packages to remove. .INPUTS System.String[] .OUTPUTS System.Int32 .NOTES Author: owen.heaume Version: 1.0.0 - Initial release #> [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $false)] [string[]]$RemoveList ) Begin { $count = 0 # get all provisioned packages $AppList = Get-AppxProvisionedPackage -Online } process { foreach ($app in $AppList) { # remove items in the list if ($RemoveList -contains $app.DisplayName) { Write-Host "Removing: $($app.DisplayName)" -ForegroundColor DarkYellow -NoNewline if ($PSCmdlet.ShouldProcess($app.displayname, 'Remove-AppxProvisionedPackage')) { try { Remove-AppxProvisionedPackage -Online -PackageName $app.PackageName -ea stop | Out-Null $count++ Write-Host ' :: Removed OK' -ForegroundColor DarkGreen } catch { Write-Error $_ } } } else { Write-Host "Retaining: $($app.DisplayName)" -ForegroundColor DarkGray } } } end { $count } } |