Powershell command to get parent processes of all processes with a given name (javaw.exe):
Get-CimInstance Win32_Process -Filter "Name = 'javaw.exe'" | select ParentProcessId
Or in a script. TYhis one takes the process name as a parameter and also shows the , this time with the parent process name:
$targetProcessName = $args[0]
$targetProcessName = $args[0]
$targetProcesses = Get-CimInstance -ClassName Win32_Process -Filter "Name = '$targetProcessName'"
foreach ($process in $targetProcesses) {
$parentProcessId = $process.ParentProcessId
$parentProcess = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $parentProcessId"
Write-Output "Process: $($process.processId) $($process.Name), Parent Process: $($ParentProcessId) $($parentProcess.Name)"
}
No comments:
Post a Comment