From 9153541837256a713b601da3f18b293d6cb1d3ed Mon Sep 17 00:00:00 2001 From: David Yoder Date: Thu, 4 Jan 2024 09:13:26 -0500 Subject: [PATCH] fix the issue --- Uninstall-UnwantedDefaultApps.ps1 | 47 +++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/Uninstall-UnwantedDefaultApps.ps1 b/Uninstall-UnwantedDefaultApps.ps1 index 4b8122f..4279146 100644 --- a/Uninstall-UnwantedDefaultApps.ps1 +++ b/Uninstall-UnwantedDefaultApps.ps1 @@ -55,20 +55,49 @@ If ( IsWindowsBuild -ge 9200 ) ForEach ( $App in $AppList ) { # Get the full name for the package and provisioned package $PackageFullName = $($(Get-AppxPackage $App).PackageFullName) - $ProPackageFullName = $($(Get-AppxProvisionedPackage -Online | Where-Object {$_.Displayname -eq $App}).PackageName | Select-Object -First 1) + $ProPackageFullName = $($(Get-AppxProvisionedPackage -Online | Where-Object {$_.Displayname -eq $App}).PackageName) - # If the package exists, uninstall it + # Make sure we have a package If ($PackageFullName) { - Write-Output “Removing package: ${PackageFullName}” - Try { Remove-AppxPackage -Package $PackageFullName } - Catch { Write-Error $_.Exception.Message } + + # Test if the package is an array + If ( $PackageFullName -is [System.Array] ) { + + # Iterate through the array of packages and uninstall each one + ForEach ( $package in $PackageFullName ) { + Write-Output “Removing package: ${package}” + Try { Remove-AppxPackage -Package $package } + Catch { Write-Error $_.Exception.Message } + } + + # If it's not an array, just uninstall the package + } Else { + Write-Output “Removing package: ${PackageFullName}” + Try { Remove-AppxPackage -Package $PackageFullName } + Catch { Write-Error $_.Exception.Message } + } } - # If the provisioned package exists, uninstall it + # Make sure we have a provisioned package If ($ProPackageFullName) { - Write-Output “Removing provisioned package: ${ProPackageFullName}” - Try { Remove-AppxProvisionedPackage -PackageName $ProPackageFullName -Online -AllUsers } - Catch { Write-Error $_.Exception.Message } + + # Test if the provisioned package is an array + If ( $ProPackageFullName -is [System.Array] ) { + + # Iterate through the array of provisioned packages and uninstall each one + ForEach ( $propackage in $ProPackageFullName ) { + Write-Output “Removing provisioned package: ${propackage}” + Try { Remove-AppxProvisionedPackage -PackageName $propackage -Online -AllUsers } + Catch { Write-Error $_.Exception.Message } + } + + # If it's not an array, just uninstall the provisioned package + } Else { + Write-Output “Removing provisioned package: ${ProPackageFullName}” + Try { Remove-AppxProvisionedPackage -PackageName $ProPackageFullName -Online -AllUsers } + Catch { Write-Error $_.Exception.Message } + } + } } } Else { Write-Output "Cannot remove Appx packages because this endpoint is not running Windows 8 or higher" }