PowerShell_Scripts/base/Stop-ProcessTree.ps1

14 lines
670 B
PowerShell
Raw Normal View History

[cmdletbinding()]param([string]$ProcessName)
$local:new_KillPIDs = @() + (Get-Process -name $processName | Select-Object -ExpandProperty ID)
$local:KillPIDs = @()
Do {
$KillPIDs += $new_KillPIDs | Where-Object { $_ -notin $KillPIDs }
Write-Verbose "Again"
Write-Verbose $new_KillPIDs -join ", "
$new_KillPIDs = $new_KillPIDs | ForEach-Object { Get-CimInstance -ClassName Win32_Process -Filter "ParentProcessId = $_" } | Select-Object -ExpandProperty ProcessId
} Until ( -not $new_KillPIDs )
Write-Verbose "Done"
start-process powershell -ArgumentList "-command","Stop-Process -Force -Id @($($KillPIDs -join '', ''))" -WindowStyle Minimized