I am learning powershell and trying to see how can variables and functions could be used. I want to print out PID for all running notepad instances, basically what is shown in PID column under Details tab in Task manager. I have written following code
$cmd = {
param($abc)
Write-Host $abc
}
$processes = Get-Process -Name notepad | Select -ExpandProperty ID
foreach ($process in $processes)
{
Start-Job -ScriptBlock $cmd -ArgumentList $process
}
I am getting following result.
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
50 Job50 BackgroundJob Running True localhost ...
52 Job52 BackgroundJob Running True localhost ...
Two issues here.
1. I only want PID, it has whole lot.
2. I expect that Id in above output is the PID but what is shown in task manager is very differnt.
Can you tell me what am I doing wrong?