title: Powershell check if file exists and replace it with new copy
body: <p>I'm trying to check if a directory exists, and if it does replace all files in that directory with updated files from another directory. </p>
  
  <pre><code>$path = "C:\mypath\config"
  if([System.IO.Directory]::Exists($path)){
      $files = Get-ChildItem -Path $path | Select-Object "Name"
      ForEach ($File in $files)
      {
          Copy-Item -Path "C:\tmp\$File" -Destination "$path\$File.txt"
      }
  }
  </code></pre>
  
  <p>I keep getting an error with the Copy-Item command because the $File is returning @{Name=filename} instead of just the name of the file. I've tried using $File.name, $File.basename, etc. but none of those appear to work. How do I get Powershell to not wrap the filename in "@{Name=}"?</p>