How to Increase number of cuncurrent powershell instance on VM? How to Increase number of cuncurrent powershell instance on VM? powershell powershell

How to Increase number of cuncurrent powershell instance on VM?


Given the following sample script:

Workflow Test-Workflow{    foreach -Parallel -ThrottleLimit 10 ( $Number in 1..20 )    {        $RandomSeconds = Get-Random -Minimum 10 -Maximum 60        InlineScript        {            $String = '{0:s}: Starting number {1:D2} for {2:D2} seconds' -f (Get-Date),$Using:Number,$Using:RandomSeconds            Write-Host -Object $String        }        Start-Sleep -Seconds $RandomSeconds        InlineScript        {            $String = '{0:s}: Stopping number {1:D2} after {2:D2} seconds' -f (Get-Date),$Using:Number,$Using:RandomSeconds            Write-Host -Object $String        }    }}Test-Workflow

You will get output similar to the following:

2017-11-28T13:27:34: Starting number 09 for 25 seconds2017-11-28T13:27:34: Starting number 10 for 36 seconds2017-11-28T13:27:34: Starting number 08 for 53 seconds2017-11-28T13:27:35: Starting number 06 for 17 seconds2017-11-28T13:27:35: Starting number 07 for 28 seconds2017-11-28T13:27:35: Starting number 05 for 33 seconds2017-11-28T13:27:35: Starting number 04 for 49 seconds2017-11-28T13:27:35: Starting number 02 for 18 seconds2017-11-28T13:27:35: Starting number 03 for 47 seconds2017-11-28T13:27:35: Starting number 01 for 45 seconds2017-11-28T13:27:52: Stopping number 06 after 17 seconds2017-11-28T13:27:55: Starting number 11 for 49 seconds2017-11-28T13:27:55: Stopping number 02 after 18 seconds2017-11-28T13:27:55: Starting number 12 for 55 seconds2017-11-28T13:28:00: Stopping number 09 after 25 seconds2017-11-28T13:28:00: Starting number 13 for 37 seconds2017-11-28T13:28:03: Stopping number 07 after 28 seconds2017-11-28T13:28:03: Starting number 14 for 46 seconds2017-11-28T13:28:08: Stopping number 05 after 33 seconds2017-11-28T13:28:08: Starting number 15 for 48 seconds2017-11-28T13:28:11: Stopping number 10 after 36 seconds2017-11-28T13:28:11: Starting number 16 for 57 seconds2017-11-28T13:28:21: Stopping number 01 after 45 seconds2017-11-28T13:28:21: Starting number 17 for 22 seconds2017-11-28T13:28:22: Stopping number 03 after 47 seconds2017-11-28T13:28:22: Starting number 18 for 39 seconds2017-11-28T13:28:24: Stopping number 04 after 49 seconds2017-11-28T13:28:24: Starting number 19 for 34 seconds2017-11-28T13:28:28: Stopping number 08 after 53 seconds2017-11-28T13:28:28: Starting number 20 for 58 seconds2017-11-28T13:28:37: Stopping number 13 after 37 seconds2017-11-28T13:28:43: Stopping number 17 after 22 seconds2017-11-28T13:28:44: Stopping number 11 after 49 seconds2017-11-28T13:28:49: Stopping number 14 after 46 seconds2017-11-28T13:28:50: Stopping number 12 after 55 seconds2017-11-28T13:28:56: Stopping number 15 after 48 seconds2017-11-28T13:28:58: Stopping number 19 after 34 seconds2017-11-28T13:29:01: Stopping number 18 after 39 seconds2017-11-28T13:29:08: Stopping number 16 after 57 seconds2017-11-28T13:29:26: Stopping number 20 after 58 seconds

As you can see from the Output, 10 instances of the loop are running concurrently even though I do not have 10 powershell.exe instances running. You can use InlineScript like in my example above to visually see when your workflow is starting and/or stopping an instance of your loop.


If I understand your question correctly, yes, there seems to be a difference between launching powershell processes and running builtin powershell (emulated) commands in a workflow. It seems to limit the process count to 5 in task manager. Maybe you can update your example with what you are running. Maybe you'd prefer jobs or start-process.

 workflow work { foreach -parallel ($i in 1..10) { powershell "sleep 10; echo done $i" }  } measure-command { work } | fl seconds Seconds           : 35 workflow work { foreach -parallel ($i in 1..10) { sleep 10; echo done $i }  } measure-command { work } | fl seconds Seconds           : 14

EDIT:

Uhh, it can be done. It's somewhat involved. You have to be administrator, and psremoting has to be enabled. Although I saw more processes run, it actually took longer to finish.

# all default to 5$wfopt = New-PSWorkflowExecutionOption -MaxSessionsPerWorkflow 20 -MaxSessionsPerRemoteNode 20 -MaxActivityProcesses 20Register-PSSessionConfiguration -Name myworkflow -SessionTypeOption $wfopt -SessionType Workflow -Forcework -PSConfigurationName myworkflow

You can use Set-PSSessionConfiguration to modify it, Get-PSSessionConfiguration to check it, and UnRegister-PSSessionConfiguration to remove it.

You could modify the default config too, Microsoft.PowerShell.Workflow, but the changes are permanent.


I using PS v5.1 and still have the same limitation.Is there a way around these limits on some newer version of PS? Maybe on PS6?

Name                           Value----                           -----PSVersion                      5.1.17134.858PSEdition                      DesktopPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}BuildVersion                   10.0.17134.858CLRVersion                     4.0.30319.42000WSManStackVersion              3.0PSRemotingProtocolVersion      2.3SerializationVersion           1.1.0.1

Follow the code and results:

foreach -parallel -throttlelimit 10 ($i in 0..20){    "start #$i"    InlineScript { "    inline #$using:i" }}start #9start #8start #7start #6start #5start #4start #3start #2start #1start #0    inline #    inline #    inline #    inline #    inline #start #10start #11start #12start #13start #14    inline #    inline #    inline #    inline #    inline #start #15start #16start #17start #18start #19    inline #    inline #    inline #start #20    inline #    inline #    inline #    inline #    inline #    inline #    inline #    inline #