pf-ProcessParent.ps1
function Get-Process_Parents($ProcessId, $name) { $allArgs = Get-CmdAllArgs $MyInvocation $targetProcesses = Invoke-WQL @allArgs -from Win32_Process -fields ProcessId, ParentProcessId, Name $pendingParents = $targetProcesses | Where-Object ParentProcessId -NE 0 | Select-Object -Unique $result = @(); while ($pendingParents) { $resultLevel = Invoke-WQL -from Win32_Process -fields ProcessId, ParentProcessId, Name -ProcessId $pendingParents.ParentProcessId | Select-Object -Unique $result += $resultLevel $pendingParents = $resultLevel | Where-Object ParentProcessId -NE 0 | Select-Object -Unique } $result } function Get-Process_Parents:::Example { Get-Process_Parents -Caption conhost* } |