简体   繁体   中英

How do I get the parent id of a process on powershell?

clear
$name = Read-host -Prompt 'Name of service'
$p = Get-process $name

$id = $p.Id
$parentId = $p.Parent.Id
echo $parentId

I've tried this, but it doesn't return anything

Get-Process doesn't contain parent ID, so you need to use Get-CimInstance

clear
$name = Read-host -Prompt 'Name of service'

$ParentProcessIds = Get-CimInstance -Class Win32_Process -Filter "Name = '$name'"
$output = $ParentProcessIds[0].ParentProcessId

Write-Host $output

Powershell how to get the ParentProcessID by the ProcessID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM