-
-
Notifications
You must be signed in to change notification settings - Fork 339
Description
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Completely removing the cbs packages will cause Windows Update to break. To resolve the problem, remove only the *.num files.
I created a script, but it doesn't include the "revert" function, so I asked Gemini to create another one trying to combine the functions of your script.
Describe the solution you'd like
A clear and concise description of what you want to happen.
Script Block 1 (My Block)
function Remove-AI-CBS-Packages {
$patterns = @('AIX', 'Recall', 'Copilot', 'CoreAI')
foreach ($pattern in $patterns) {
$packages = Get-WindowsPackage -Online -ErrorAction SilentlyContinue | Where-Object { $_.PackageName -like $pattern }
foreach ($pkg in $packages) {
try {
Remove-WindowsPackage -Online -PackageName $pkg.PackageName -NoRestart -ErrorAction Stop >$null 2>$null
} catch {
Start-Process -FilePath "dism.exe" -ArgumentList "/Online", "/Remove-Package", "/PackageName:$($pkg.PackageName)", "/NoRestart", "/Quiet" -WindowStyle Hidden -Wait 2>$null
}
}
}
foreach ($pattern in $patterns) {
$files = Get-ChildItem "$env:windir\servicing\Packages" -Filter "$pattern*.mum" -ErrorAction SilentlyContinue
foreach ($file in $files) {
$filePath = $file.FullName
try {
takeown /f "$filePath" /a > $null 2>$null
icacls "$filePath" /grant "Administradores:F" /c > $null 2>$null
Remove-Item -Path $filePath -Force 2>$null
} catch {}
}
}
}
Script Block 2 (Gemini)
function Remove-AI-CBS-Packages {
param([switch]$revert)
$patterns = @('*AIX*', '*Recall*', '*Copilot*', '*CoreAI*')
$regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages'
if (!$revert) {
Write-Host "Starting deep uninstallation of AI packages..." -ForegroundColor Cyan
# PHASE 1: Unhide and Break Links in Registry
$ProgressPreference = 'SilentlyContinue'
Get-ChildItem $regPath | ForEach-Object {
$pkgName = $_.PSChildName
# Check if the package matches any of our patterns
foreach ($pattern in $patterns) {
if ($pkgName -like $pattern) {
$value = try { Get-ItemPropertyValue "registry::$($_.Name)" -Name Visibility -ErrorAction Stop } catch { $null }
# If hidden (2), make it visible (1) and remove owners
if ($value -eq 2) {
Set-ItemProperty "registry::$($_.Name)" -Name Visibility -Value 1 -Force
New-ItemProperty "registry::$($_.Name)" -Name DefVis -PropertyType DWord -Value 2 -Force | Out-Null
Remove-Item "registry::$($_.Name)\Owners" -Force -ErrorAction SilentlyContinue
Remove-Item "registry::$($_.Name)\Updates" -Force -ErrorAction SilentlyContinue
}
# PHASE 2: Logical Removal
try {
Write-Host "Removing package: $pkgName" -ForegroundColor Yellow
Remove-WindowsPackage -Online -PackageName $pkgName -NoRestart -ErrorAction Stop >$null 2>$null
} catch {
# Fallback to DISM (more robust in some environments)
dism.exe /Online /Remove-Package /PackageName:$pkgName /NoRestart /Quiet
}
}
}
}
# PHASE 3: Physical File Cleanup with Takeown
Write-Host "Cleaning up residual files (.mum)..." -ForegroundColor Gray
foreach ($pattern in $patterns) {
$files = Get-ChildItem "$env:windir\servicing\Packages" -Filter "$pattern*.mum" -ErrorAction SilentlyContinue
foreach ($file in $files) {
$filePath = $file.FullName
try {
# Ensure permissions to delete system files
takeown /f "$filePath" /a > $null 2>$null
icacls "$filePath" /grant "Administrators:F" /c > $null 2>$null
Remove-Item -Path $filePath -Force 2>$null
} catch {}
}
}
} else {
Write-Host "Revert Mode: To revert, you must use Windows Update or a recovery image." -ForegroundColor Orange
}
}
Additional context
Add any other context or screenshots about the feature request here.
I tested the first script at the company where I work and it doesn't break Windows Update. If it's not possible to implement this, separate the action of this block from the rest of the script.