title: Powershell check whether a file exists
body: <p>On Windows 7 x64, Powershell 3.0:<br><br>
  I have a directory where I download files to, this is done with a .csv file.
  A sample of the files is:</p>
  
  <pre><code>008KS04.zip
  008KS05.zip
  008KS06.zip
  008KS07.zip
  008KS08.zip
  008KS09.zip
  </code></pre>
  
  <p>I have a Csv, op wich this is a sample:</p>
  
  <pre><code>Documentnummer,Versie,Status,Geocode,IDS datum,Documentgroep (Omsch),Documenttype (Wrd),Tekeningnummer
  550164,I,AB,008,26.03.2016,Themalagen OI,KS,008KS09.zip
  550163,D,AB,008,19.07.2013,Themalagen OI,KS,008KS08.zip
  550162,D,AB,008,19.07.2013,Themalagen OI,KS,008KS07.zip
  550161,C,AB,008,19.07.2013,Themalagen OI,KS,008KS06.zip
  550160,D,AB,008,19.07.2013,Themalagen OI,KS,008KS05.zip
  550159,E,AB,008,15.08.2014,Themalagen OI,KS,008KS04.zip
  </code></pre>
  
  <p>So, lets say the files are in c:\test\<br>
  and the csv in C:\drawings.csv<br>
  I want the files that are missing in a csv, lets say C:\missing.csv<br>
  At first I tried with one drawing in a variable:</p>
  
  <pre><code>$drawnr = '008KS09.zip'
  $destcsv = "C:\missing.csv"
  Set-Location C:\test
      If(Test-Path -Path ${drawnr}) {
         Write-Output "${drawnr}'.zip' exists"
  
    } Else {
  
      Write-Output "${drawnr}'.zip' doesnt exist"
      ${drawnr} | Export-Csv $destcsv -Append -NoTypeInformation
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/R2RDK.png" rel="nofollow noreferrer">The output when having an existing and a non existsing drawing in the variable</a><br>
  This works perfect, see image but using the CSV as input, I can't get it to work.<br>
  This is what I have so far:</p>
  
  <pre><code>$sourcecsv = 'C:\drawings.csv'
  $destcsv = 'C:\missing.csv'
  Set-Location 'C:\test\'
  
  Import-Csv $sourcecsv | Select-object -Property Tekeningnummer | ForEach {
  
      Write-Output "${_} is the current object" #For Testing purpuse
  If (Test-Path -Path ${_}) {
  
      Write-Output "${_} does exist"
  
    } Else {
  
      Write-Output "${_} doesnt exist"
      ${_} | Export-Csv $destcsv -Append -NoTypeInformation
      }
  }
  </code></pre>
  
  <p>This tells me that none of the files exist, while all do exist.<br>
  See the picture to see the output of PowerShell and the content written to the missing.csv<br>
  <a href="https://i.stack.imgur.com/hkECe.jpg" rel="nofollow noreferrer">The picture of the output where all files are reported as non existend</a></p>