Powershell Throttle Multi thread jobs via job completion

后端 未结 6 1509
情歌与酒
情歌与酒 2020-12-07 03:23

All the tuts I have found use a pre defined sleep time to throttle jobs. I need the throttle to wait until a job is completed before starting a new one. Only 4 jobs can be r

6条回答
  •  萌比男神i
    2020-12-07 04:19

    You can test the following :

    $servers = Get-Content "C:\temp\flashfilestore\serverlist.txt"
    $scriptBlock = { #DO STUFF }
    invoke-command -computerName $servers -scriptblock $scriptBlock -jobname 'YourJobSpecificName' -throttlelimit 4 -AsJob
    

    This command uses the Invoke-Command cmdlet and its AsJob parameter to start a background job that runs a scriptblock on numerous computers. Because the command must not be run more than 4 times concurrently, the command uses the ThrottleLimit parameter of Invoke-Command to limit the number of concurrent commands to 4.

    Be careful that the file contains the computer names in a domain.

提交回复
热议问题