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
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.