title: Powershell copy and rename files
body: <p>I'm trying to copy files from a source folder to a destination folder, and rename the files in the process.</p>
  
  <pre><code>$Source = "C:\Source"
  
  $File01 = Get-ChildItem $Source | Where-Object {$_.name -like "File*"}
  
  $Destination = "\\Server01\Destination"
  
  Copy-Item "$Source\$File01" "$Destination\File01.test" -Force -
  Confirm:$False -ErrorAction silentlyContinue
  if(-not $?) {write-warning "Copy Failed"}
  else {write-host "Successfully moved $Source\$File01 to 
  $Destination\File01.test"}
  </code></pre>
  
  <p>The problem is that since <code>Get-ChildItem</code> doesn't throw an error message if the file is not found, but rather just gives you a blank, I end up with a folder called <code>File01.test</code> in destination if no file named <code>File*</code> exists in <code>$Source</code>.</p>
  
  <p>If it does exist, the copy operation carries out just fine. But I don't want a folder to be created if no matching files exist in <code>$Source</code>, rather I just want an error message logged in a log file, and no file operation to occur.</p>