Skip to content

Instantly share code, notes, and snippets.

View jhickson's full-sized avatar

Jos Hickson jhickson

  • London
  • 01:40 (UTC +01:00)
View GitHub Profile
@jhickson
jhickson / kill_children.ps1
Last active December 29, 2018 13:50
Kill all child processes of current Powershell script/session
function KillChildren
{
Param(
[Parameter(Mandatory=$True,Position=1)]
[int]$parentProcessId
)
Get-WmiObject win32_process | where {$_.ParentProcessId -eq $parentProcessId} | ForEach { KillChildren $_.ProcessId }
Get-WmiObject win32_process | where {$_.ParentProcessId -eq $parentProcessId} | ForEach { Stop-Process $_.ProcessId 2>$null }
}