title: Using Start-Job on script
body: <p>Using a script in PowerShell to recursivly pass through all folders on multiple NAS boxes to display every folder with its full path in an <code>Out-File</code>. 
  Using the <code>Get-FolderEntry</code> script I found <a href="https://gallery.technet.microsoft.com/scriptcenter/Get-FolderEntry-List-all-bce0ff43#content" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Since I have multiple NAS boxes with more then 260 chars in the filename/pathlength I figured I'd use multithreading to speed the process up. </p>
  
  <p><strong>Code:</strong></p>
  
  <pre class="lang-cs prettyprint-override"><code>. C:\Users\mdevogea\Downloads\Get-FolderEntry.ps1
  # list with the servers
  $Computers = Get-Content C:\Users\mdevogea\Desktop\servers.txt
  
  # scriptblock calling on get-FolderEntry
  $sb = {
      param ($Computer, $fname)
      C:\Users\mdevogea\Downloads\Get-FolderEntry.ps1 -Path $Computer |
          fl | Out-File -Append -Width 1000 -FilePath $fname
  }
  
  foreach($Computer in $Computers)
  {
      $name = $Computer.Replace("\", "")
      $fname = $("C:\Users\mdevogea\Desktop\" + $name + ".txt")
      #Get-FolderEntry -Path $Computer | fl | Out-File -Append -Width 1000 $fname
  
      $res = Start-Job $sb -ArgumentList $Computer, $fname
  }
  
  # Wait for all jobs
  Get-Job
  while(Get-Job -State "Running")
  {
      Write-Host "Running..."
      Start-Sleep 2
  }
  # Get all job results
  Get-Job | Receive-Job | Out-GridView
  </code></pre>
  
  <p>So far: </p>
  
  <ol>
  <li><p>I either get empty files with the correct naming of the file.</p></li>
  <li><p>I get the correct named file with the code of <code>Get-FolderEntry</code> in it.</p></li>
  <li><p>I get errors depend on what I pass along to the scriptblock.</p></li>
  </ol>
  
  <p>In short, it's probably stupid but don't see it.</p>