title: Split-Pipeline parallel jobs script won't finish the last job
body: <p>So I've been using Split-Pipeline module for some time now, and what bothers me about it, rarely does it really finish. I always get stuck with the last job in the queue hanging and have to either stop the script or kill ISE:</p>
  
  <p>VERBOSE: Split-Pipeline: Jobs = 1; Load = End; Queue = 0</p>
  
  <p>example: 300 servers, running a scan for hotfixes on them using split-pipeline. I'm using pretty standard parameters:</p>
  
  <p>$servers | Split-Pipeline -Verbose -Count 10 { process {#some code for scanning#}}</p>
  
  <p>So 10 jobs each loaded with 30 servers, first lets say 250 servers are scanned really fast, then it slows down a little and when the last job remains only, it never finishes...</p>
  
  <p>Anyone experienced something similar? I've tested the same on several machines and it's always the same so I don't think it's related to the machine running the script.</p>
  
  <p>EDIT: heres the code</p>
  
  <pre><code>$servers = (Get-Clipboard).trim() #server1..100
  $KB = (Get-Clipboard).trim() -split ', ' #KB4022714, KB4022717, KB4022718, KB4022722, KB4022727, KB4022883, KB4022884, KB4022887, KB4024402, KB4025339, KB4025342, KB4021903, KB4021923, KB4022008, KB4022010, KB4022013, KB3217845
  
  $servers | Split-Pipeline -Verbose -Variable KB -Count 10 { process {
          $hash = [ordered]@{}
          try
          {
              $hash.Hostname = $_
              $os = gwmi win32_operatingsystem -ComputerName $_ -ErrorAction Stop
              $hash.OS = $os.Caption
              $hash.Architecture = $os.OSArchitecture
              $today = [Management.ManagementDateTimeConverter]::ToDateTime($os.LocalDateTime)
              $hash.LastReboot = [Management.ManagementDateTimeConverter]::ToDateTime($os.LastBootUpTime)
              $hash.DaysSinceReboot = ($today - $hash.LastReboot).Days
          }
          catch
          {
              $hash.OS = $Error[0]
              $hash.Architecture = 'N/A'
              $hash.LastReboot = 'N/A'
              $hash.DaysSinceReboot = 'N/A'
          }
  
          try
          {
              $hash.PendingReboot = icm -cn $_ {
                  if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA SilentlyContinue) { return $true }
                  if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA SilentlyContinue) { return $true }
                  if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -Ea SilentlyContinue) { return $true }
                  try
                  {
                      $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
                      $status = $util.DetermineIfRebootPending()
                      if(($status -ne $null) -and $status.RebootPending)
                      {
                          return $true
                      }
                  }
                  catch{}
                  return $false
              }
          }
          catch
          {
              $hash.PendingReboot = 'N/A'
          }
  
          try
          {
              $hotfix = Get-HotFix -ComputerName $_ -Id $KB -ErrorAction Stop
              if ($hotfix)
              {
                  $hash.Hotfix = $hotfix.HotFixID -join ','
              }
              else
              {
                  $hash.Hotfix = "No Hotfix from the list applied"
              }        
          }
          catch
          {
              $hash.Hotfix = $Error[0]
          }
          $obj = New-Object -TypeName PSObject -Property $hash
          $obj | Export-Csv c:\temp\hotfixes.csv -NoTypeInformation -Append -Force
      }
  }
  </code></pre>