mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 14:45:52 -06:00
[MicroWin] Add try-catch block for AppX packages (#2560)
This commit is contained in:
parent
b0d54e41ad
commit
4d2ea15e19
@ -132,42 +132,49 @@ function Remove-ProvisionedPackages() {
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Remove-ProvisionedPackages
|
Remove-ProvisionedPackages
|
||||||
#>
|
#>
|
||||||
$appxProvisionedPackages = Get-AppxProvisionedPackage -Path "$($scratchDir)" | Where-Object {
|
try
|
||||||
$_.PackageName -NotLike "*AppInstaller*" -AND
|
{
|
||||||
$_.PackageName -NotLike "*Store*" -and
|
$appxProvisionedPackages = Get-AppxProvisionedPackage -Path "$($scratchDir)" | Where-Object {
|
||||||
$_.PackageName -NotLike "*dism*" -and
|
$_.PackageName -NotLike "*AppInstaller*" -AND
|
||||||
$_.PackageName -NotLike "*Foundation*" -and
|
$_.PackageName -NotLike "*Store*" -and
|
||||||
$_.PackageName -NotLike "*FodMetadata*" -and
|
$_.PackageName -NotLike "*dism*" -and
|
||||||
$_.PackageName -NotLike "*LanguageFeatures*" -and
|
$_.PackageName -NotLike "*Foundation*" -and
|
||||||
$_.PackageName -NotLike "*Notepad*" -and
|
$_.PackageName -NotLike "*FodMetadata*" -and
|
||||||
$_.PackageName -NotLike "*Printing*" -and
|
$_.PackageName -NotLike "*LanguageFeatures*" -and
|
||||||
$_.PackageName -NotLike "*Wifi*" -and
|
$_.PackageName -NotLike "*Notepad*" -and
|
||||||
$_.PackageName -NotLike "*Foundation*" -and
|
$_.PackageName -NotLike "*Printing*" -and
|
||||||
$_.PackageName -NotLike "*YourPhone*" -and
|
$_.PackageName -NotLike "*Wifi*" -and
|
||||||
$_.PackageName -NotLike "*Xbox*" -and
|
$_.PackageName -NotLike "*Foundation*" -and
|
||||||
$_.PackageName -NotLike "*WindowsTerminal*" -and
|
$_.PackageName -NotLike "*YourPhone*" -and
|
||||||
$_.PackageName -NotLike "*Calculator*" -and
|
$_.PackageName -NotLike "*Xbox*" -and
|
||||||
$_.PackageName -NotLike "*Photos*" -and
|
$_.PackageName -NotLike "*WindowsTerminal*" -and
|
||||||
$_.PackageName -NotLike "*VCLibs*" -and
|
$_.PackageName -NotLike "*Calculator*" -and
|
||||||
$_.PackageName -NotLike "*Paint*" -and
|
$_.PackageName -NotLike "*Photos*" -and
|
||||||
$_.PackageName -NotLike "*Gaming*" -and
|
$_.PackageName -NotLike "*VCLibs*" -and
|
||||||
$_.PackageName -NotLike "*Extension*" -and
|
$_.PackageName -NotLike "*Paint*" -and
|
||||||
$_.PackageName -NotLike "*SecHealthUI*"
|
$_.PackageName -NotLike "*Gaming*" -and
|
||||||
|
$_.PackageName -NotLike "*Extension*" -and
|
||||||
|
$_.PackageName -NotLike "*SecHealthUI*"
|
||||||
}
|
}
|
||||||
|
|
||||||
$counter = 0
|
$counter = 0
|
||||||
foreach ($appx in $appxProvisionedPackages) {
|
foreach ($appx in $appxProvisionedPackages) {
|
||||||
$status = "Removing Provisioned $($appx.PackageName)"
|
$status = "Removing Provisioned $($appx.PackageName)"
|
||||||
Write-Progress -Activity "Removing Provisioned Apps" -Status $status -PercentComplete ($counter++/$appxProvisionedPackages.Count*100)
|
Write-Progress -Activity "Removing Provisioned Apps" -Status $status -PercentComplete ($counter++/$appxProvisionedPackages.Count*100)
|
||||||
try {
|
try {
|
||||||
Remove-AppxProvisionedPackage -Path "$scratchDir" -PackageName $appx.PackageName -ErrorAction SilentlyContinue
|
Remove-AppxProvisionedPackage -Path "$scratchDir" -PackageName $appx.PackageName -ErrorAction SilentlyContinue
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Application $($appx.PackageName) could not be removed"
|
Write-Host "Application $($appx.PackageName) could not be removed"
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Write-Progress -Activity "Removing Provisioned Apps" -Status "Ready" -Completed
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
# This can happen if getting AppX packages fails
|
||||||
|
Write-Host "Unable to get information about the AppX packages. MicroWin processing will continue, but AppX packages will not be processed"
|
||||||
}
|
}
|
||||||
Write-Progress -Activity "Removing Provisioned Apps" -Status "Ready" -Completed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Copy-ToUSB([string]$fileToCopy) {
|
function Copy-ToUSB([string]$fileToCopy) {
|
||||||
|
Loading…
Reference in New Issue
Block a user