Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Last active March 12, 2018 23:47
Show Gist options
  • Save Jaykul/1f368143b7fe7e620f0c to your computer and use it in GitHub Desktop.
Save Jaykul/1f368143b7fe7e620f0c to your computer and use it in GitHub Desktop.
ChildProcess
function Stop-ChildProcess {
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[Parameter(ValueFromPipelineByPropertyName=$true, ParameterSetName="Name")]
[String[]]$Name,
[Parameter(ValueFromPipelineByPropertyName=$true, ParameterSetName="ID")]
[Alias("ProcessID")]
[Int[]]$ID,
[Switch]$IncludeParent
)
process {
$null = $PSBoundParameters.Remove("IncludeParent")
Get-ChildProcess @PSBoundParameters -Passthru:$IncludeParent | Stop-Process
}
}
function Get-ChildProcess {
[CmdletBinding(SupportsShouldProcess=$true, DefaultParameterSetName="ID")]
param(
[Parameter(ValueFromPipelineByPropertyName=$true, ParameterSetName="Name", Position=0)]
[String[]]$Name,
[Parameter(ValueFromPipelineByPropertyName=$true, ParameterSetName="ID", Position=0)]
[Alias("ProcessID")]
[Int[]]$ID,
[Switch]$Passthru
)
process {
$(
$null = $PSBoundParameters.Remove("Passthru")
foreach($ID in Get-Process @PSBoundParameters | % Id) {
Get-WmiObject Win32_Process -Filter "ParentProcessID=${ID}" | Select ProcessID
}
) | Get-ChildProcess -Passthru
if($Passthru) {
Get-Process @PSBoundParameters
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment