Files
winutil/functions/public/Invoke-WPFAppxRemoval.ps1
T
2026-06-21 18:34:27 +03:00

44 lines
1.5 KiB
PowerShell

function Invoke-WPFAppxRemoval {
<#
.SYNOPSIS
Removes the selected AppX packages in a background runspace.
#>
if ($sync.ProcessRunning) {
$msg = "A process is currently running. Please wait for it to finish."
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
return
}
$selected = @($sync.selectedAppx)
if ($selected.Count -eq 0) {
$msg = "Please select the AppX packages you wish to remove."
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
return
}
$totalSteps = $selected.Count
$completedSteps = 0
$handle = Invoke-WPFRunspace -ParameterList @(("selected", $selected), ("completedSteps", $completedSteps), ("totalSteps", $totalSteps)) -ScriptBlock {
param($selected, $completedSteps, $totalSteps)
$sync.ProcessRunning = $true
for ($i = 0; $i -lt $selected.Count; $i++) {
$key = $selected[$i]
$appInfo = $sync.configs.appxHashtable.$key
$packageId = $appInfo.PackageId
Write-Host "Removing $packageId"
Get-AppxPackage -Name $packageId -AllUsers | Remove-AppxPackage -AllUsers
}
$sync.ProcessRunning = $false
Write-Host "================================="
Write-Host "-- AppX Removal Finished ---"
Write-Host "================================="
}
}