additional error handling when removing cbs packages

This commit is contained in:
zoicware
2025-12-09 23:48:13 -05:00
committed by GitHub
parent 31a32b0fef
commit 57e06ed07e

View File

@@ -1131,7 +1131,9 @@ function Remove-AI-CBS-Packages {
$regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages' $regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages'
$ProgressPreference = 'SilentlyContinue' $ProgressPreference = 'SilentlyContinue'
Get-ChildItem $regPath | ForEach-Object { Get-ChildItem $regPath | ForEach-Object {
$value = try { Get-ItemPropertyValue "registry::$($_.Name)" -Name Visibility -ErrorAction SilentlyContinue } catch {} $value = try { Get-ItemPropertyValue "registry::$($_.Name)" -Name Visibility -ErrorAction Stop } catch { $null }
if ($value -ne $null) {
if ($value -eq 2 -and $_.PSChildName -like '*AIX*' -or $_.PSChildName -like '*Recall*' -or $_.PSChildName -like '*Copilot*' -or $_.PSChildName -like '*CoreAI*') { if ($value -eq 2 -and $_.PSChildName -like '*AIX*' -or $_.PSChildName -like '*Recall*' -or $_.PSChildName -like '*Copilot*' -or $_.PSChildName -like '*CoreAI*') {
Set-ItemProperty "registry::$($_.Name)" -Name Visibility -Value 1 -Force Set-ItemProperty "registry::$($_.Name)" -Name Visibility -Value 1 -Force
New-ItemProperty "registry::$($_.Name)" -Name DefVis -PropertyType DWord -Value 2 -Force New-ItemProperty "registry::$($_.Name)" -Name DefVis -PropertyType DWord -Value 2 -Force
@@ -1139,16 +1141,29 @@ function Remove-AI-CBS-Packages {
Remove-Item "registry::$($_.Name)\Updates" -Force -ErrorAction SilentlyContinue Remove-Item "registry::$($_.Name)\Updates" -Force -ErrorAction SilentlyContinue
try { try {
Remove-WindowsPackage -Online -PackageName $_.PSChildName -NoRestart -ErrorAction Stop *>$null Remove-WindowsPackage -Online -PackageName $_.PSChildName -NoRestart -ErrorAction Stop *>$null
Get-ChildItem "$env:windir\servicing\Packages" -Filter "*$($_.PSChildName)*" | Remove-Item $_.FullName -Force -ErrorAction SilentlyContinue $paths = Get-ChildItem "$env:windir\servicing\Packages" -Filter "*$($_.PSChildName)*" -ErrorAction SilentlyContinue
foreach ($path in $paths) {
if ($path) {
Remove-Item $path.FullName -Force -ErrorAction SilentlyContinue
}
}
} }
catch { catch {
#fallback to dism when user is using powershell 7 #fallback to dism when user is using powershell 7
dism.exe /Online /Remove-Package /PackageName:$($_.PSChildName) /NoRestart /Quiet dism.exe /Online /Remove-Package /PackageName:$($_.PSChildName) /NoRestart /Quiet
Get-ChildItem "$env:windir\servicing\Packages" -Filter "*$($_.PSChildName)*" | Remove-Item $_.FullName -Force -ErrorAction SilentlyContinue $paths = Get-ChildItem "$env:windir\servicing\Packages" -Filter "*$($_.PSChildName)*" -ErrorAction SilentlyContinue
foreach ($path in $paths) {
if ($path) {
Remove-Item $path.FullName -Force -ErrorAction SilentlyContinue
}
}
} }
} }
} }
}
} }
} }
@@ -2229,6 +2244,7 @@ else {
'WorkloadsSessionHost.exe' 'WorkloadsSessionHost.exe'
'WebViewHost.exe' 'WebViewHost.exe'
'aimgr.exe' 'aimgr.exe'
'AppActions.exe'
) )
foreach ($procName in $aiProcesses) { foreach ($procName in $aiProcesses) {
taskkill /im $procName /f *>$null taskkill /im $procName /f *>$null