title: Error on running Pester test using foreach-object -parallel
body: <p>I have this infrastructure pester test. Code for demonstration purpose:</p>
  <pre class="lang-bsh prettyprint-override"><code>Describe 'WEB-Tests' {
      $servers = 'ServerA','ServerB'
      $sessions = @()
      foreach ($server in $servers) {
          $sessions += New-PSSession -ComputerName $server
      }
      $sessions | foreach-object {
          Context &quot; Service is Running on $($_.ComputerName)&quot; {
              $service = invoke-command -session $_ -scriptblock { get-service 'some service' }
              It &quot;Service $($service.Name) should be Running&quot; {
                  $service.Status | Should be &quot;Running&quot;
              }
          }
      }
  }
  </code></pre>
  <p>This works fine. If I replace the $sessions|foreach-object with $sessions|foreach-object -Parallel, i get this error -</p>
  <pre><code>New-PesterState: C:\Program Files\WindowsPowerShell\Modules\Pester\4.9.0\Functions\Context.ps1:77:128
  Line |
    77 |  … '] .) -TestNameFilter $null -TagFilter @() -SessionState SessionState
       |                                                             ~~~~~~~~~~~~
       | Cannot process argument transformation on parameter 'SessionState'. Cannot convert the &quot;SessionState&quot; value of type &quot;System.String&quot; to type
       | &quot;System.Management.Automation.SessionState&quot;.
  
  Exception: The Context command may only be used from a Pester test script.
  </code></pre>
  <p>Please suggest on how to achieve parallelism here as there are hundreds of servers.</p>
  <p>RESOLVED-I figured out a workaround by using jobs and it serves the purpose.</p>
  <pre><code>Describe 'WEB-Tests' {
      $servers = 'ServerA','ServerB'
      $sessions = @()
      foreach ($server in $servers) {
          $sessions += New-PSSession -ComputerName $server
      }
      Get-Job | Remove-Job  
      invoke-command -session $sessions -scriptblock { get-service W3SVC,WAS } -AsJob  
      $j = Get-Job | wait-job
      ($results = $j | Receive-Job) | out-null
      Context &quot;IIS Services are Running&quot; {
          foreach ($result in $results) {      
              It &quot;Service $($result.Name) should be Running on $($result.PSComputerName)&quot; {
                  $result.Status | Should be &quot;Running&quot;
              }        
          }
      }
  }
  </code></pre>