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