How can I determine which processes are started by the Start-Job command?

I have a (inherited) PowerShell script that calls other PowerShell scripts, invoking them using the Start-Joband cmdlet -FilePath. For example, I have a script that does nothing:

Start-Sleep -Seconds 86400

What can I call through the task:

PS> Start-Job -Name "Test Job" -FilePath ".\Wait-AllDay.ps1"

Id Name     PSJobTypeName State   HasMoreData Location  Command                        
-- ----     ------------- -----   ----------- --------  -------                        
2  Test Job BackgroundJob Running True        localhost Start-Sleep...

PS> Get-Job -Id 2

State         : Running
HasMoreData   : True
StatusMessage : 
Location      : localhost
Command       : Start-Sleep -Seconds (60*60*24)
JobStateInfo  : Running
Finished      : System.Threading.ManualResetEvent
InstanceId    : 0c0e2c32-cbc5-4d70-b7cb-28771626cf20
Id            : 2
Name          : Test Job
ChildJobs     : {Job3}
PSBeginTime   : 25/01/2016 15:06:22
PSEndTime     : 
PSJobTypeName : BackgroundJob

Is there a simple and reliable way to find out which process is associated with this work (which, in my opinion, will be additional powershell.exe )? Obviously, this is easy when testing with only one task, but on the server I can have many such starts at the same time.

Why do I want to do this / know?

, , . , Start-Job, , ( ) , . , , , , , .

, , , , .

+4
2

, " , " .

, , , , .

  • , :

    "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Version 4.0 -s -NoLogo -NoProfile

  • powershell.exe powershell_ise.exe, . , , script, . , ~ 4 powershell.exe.

  • , (, Get-Job, ), , ; 1-2 .

, , .

+1

*-Job , . Get-Job :

PS C:\> Get-Job

Id   Name    PSJobTypeName   State       HasMoreData   Location      Command
--   ----    -------------   -----       -----------   --------      -------
2    Job2    BackgroundJob   Running     False         localhost     Do-Some
4    Job4    BackgroundJob   Completed   True          localhost     Get-Other

Command , .

(Get-Job -Id 2).Command

State (, , , ,...). HasMoreData , , Receive-Job.

Receive-Job -Id 4

Stop-Job Remove-Job .

. .

+3

Source: https://habr.com/ru/post/1625853/


All Articles