[英]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 Get-Process 不包含父 ID,因此您需要使用 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 Powershell 如何通过ProcessID获取ParentProcessID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.