Search code examples
powershellstart-processselect-string

Question about using PowerShell Select-String, exiftool(-k)


In a PowerShell script I'm trying to filter the output of the exiftool(-k).exe command below, using Select-String.

I've tried numerous permutations, but none work, and I always see the unfiltered output. What do I need to do to filter the output of this command?

Start-Process -FilePath "C:\PowerShell\exiftool(-k).exe" -ArgumentList test.jpg |
  Select-String -pattern 'GPS' -SimpleMatch

Solution

  • The naming is inconvenient. Rename it to exiftool.exe and run it without start-process.

    rename-item 'exiftool(-k).exe' exiftool.exe    
    
    C:\Users\bfbarton\PowerShell\exiftool.exe test-jpg | Select-String GPS 
    

    Or

    $env:path += ';C:\Users\bfbarton\PowerShell'
    exiftool test.jpg | Select-String GPS
    

    The website recommends to 'rename to "exiftool.exe" for command-line use'. https://exiftool.org . Even in unix, it wouldn't work without escaping the parentheses.

    There's also the option of using the call operator. Using tab completion actually does this:

    & '.\exiftool(-k).exe' test.jpg | select-string gps