title: How to move files from folder to folder based on name and Basename
body: <p>I am trying to move files that have the same basename from a failed folder to a good folder. The code at the moment is moving the FailedDocs folder to the GoodDocs, but I would only like the files within.</p>
  
  <p>Example files below;</p>
  
  <ul>
  <li>test.pdf (name)</li>
  <li>test.pdf.xml (basename)</li>
  </ul>
  
  <p>Files to be moved when test.pdf.xml (when basename is used becomes test.pdf) and equals test.pdf within the Good Folder.</p>
  
  <pre><code>$sourceFiles = @("C:\Temp\FailedDocs")
  $destinationFiles = @("C:\Temp\GoodDocs")
  
  function Perform-File-Move {
      for ($i = 0; $i -lt $sourceFiles.Count; $i++) {
          Get-ChildItem $($sourceFiles[$i]) -Recurse | Where-Object {
              $destinationFiles.Name -eq $sourceFiles.BaseName
          } | ForEach-Object {
              if ($destinationFiles.Name -eq $sourceFiles.BaseName) {
                  Move-Item -Path $($sourceFiles[$i]) -Destination
                  $($destinationFiles[$i]) -Force
              } else {
                  Write-Host "Nothing to Move"
              }
          }
      }
  }
  
  Perform-File-Move
  </code></pre>