I have a problem with the Get-Process command in Powershell, when i use it inside a Job.
I would like to get a process by PID, so i am doing the below:
$MyProcess = Get-Process | Where-Object { $_.Id -eq $parentProcessID }
The above, when it is called as a command from a Powershell script, returns me the process expected.
If I use the exact same command inside a Start-Job{} block then it gives me null, even for a process that is running. For example:
Start-Job { $parentProcessID = $args $MyProcess = Get-Process | Where-Object { $_.Id -eq $parentProcessID } if($MyProcess -eq $null) { echo "Nothing returned" } } -ArgumentList "$parentProcessID"
Is there anything i am missing here? Has anyone run into similar situation before?
Any insights appreciated.
Thanks.