title: Move X files from one folder to another in Powershell
body: <p>I have a folder <strong>A</strong> with 75000 files which are to be processed. I have 4 folders (A,B,C,D) alongside it which can process 3000 files at a time. </p>
  
  <p>I want a script to take 3000 files from A and put it in B. It should then take another 3000 files and put in C, then D and finally E </p>
  
  <p>Below is the code I have so far. this takes 10 files and moves them into B, but then it just sits forever without putting any files into C,D or E.</p>
  
  <p>Is there a way to quit out of the EnumerateFiles section of code? I just want the first X files it finds to get moved, I don't care about how many files are in A.</p>
  
  <p>Any idea?</p>
  
  <pre><code>$dirBase = "\\networkDir\A\"
  $dirProc1 = "\\networkDir\B\"
  $dirProc2 = "\\networkDir\C\"
  $dirProc3 = "\\networkDir\D\"
  $dirProc4 = "\\networkDir\E\"
  
  cd $dirBase
  
  $directoryInfo1 = Get-ChildItem $dirProc1 | Measure-Object
  $directoryInfo2 = Get-ChildItem $dirProc2 | Measure-Object
  $directoryInfo3 = Get-ChildItem $dirProc3 | Measure-Object
  $directoryInfo4 = Get-ChildItem $dirProc4 | Measure-Object
  
  if ($directoryInfo1.count -eq 0) {
      MoveFiles $dirBase $dirProc1
  } 
  if ($directoryInfo2.count -eq 0) {
      MoveFiles $dirBase $dirProc2
  } 
  if ($directoryInfo3.count -eq 0) {
      MoveFiles $dirBase $dirProc3
  } 
  if ($directoryInfo4.count -eq 0) {
      MoveFiles $dirBase $dirProc4
  } 
  
  function MoveFiles([string]$srcDir, [string]$dest)
  {
      $FileLimit = 10    
      $Counter = 0
  
      [IO.Directory]::EnumerateFiles($srcDir) | Where-Object {$Counter -lt $FileLimit} | %{ 
      #Get-ChildItem $srcDir | Select-Object -first $FileLimit | %{ 
  
          Move-Item $_ -destination $dest
          $Counter++
  
      }
  }
  </code></pre>