Skip to content

Instantly share code, notes, and snippets.

@jacefreeman
Last active August 29, 2015 14:16
Show Gist options
  • Save jacefreeman/8f05fc560340f7abcea5 to your computer and use it in GitHub Desktop.
Save jacefreeman/8f05fc560340f7abcea5 to your computer and use it in GitHub Desktop.
<# Import a CSV and use it to check for a files existence, writing the output to a file #>
<# Seems to output whole array instead of just the value, annoying #>
<# Fail 1#>
$csv = Import-csv .\no_files.csv | select-object -Property DocumentNo, AttachNo, AttTitle, FilePath | ForEach-Object { if ((Test-Path -Path $_.FilePath) -eq $true) { write-host "$_.FilePath exists"} else { write-host "$_.FilePath missing"}} | Export-CSV recfind_ledger.csv -NoTypeInformation
<# Succesful Code #>
Import-csv '.\no_files.csv' | select @{n='DecRegistrationNo';e={$_.DecRegistrationNo}}, @{n='Path'; e={$_.FilePath}}, @{n='Exists';e={Test-Path -LiteralPath $_.FilePath}} | Export-CSV 'csv_out.csv' -NoType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment