1

When in Powershell I can run the following command

.\exiftool.exe '-GPSLatitude*=56.9359839838' '-GPSLongitude*=-4.4651045874' DSC01008.JPG '-overwrite_original_in_place'

enter image description here

This works just fine, and the placement of single quotes around those params are required. I went through various iterations of different placements and the above is the only way I could get it to work.

My issue is -> That I'm trying to replace those values with programmatic values. As in something like the following.

$lat = 56.9359839838
$lon = -4.4651045874
$fileName = 'DSC01008.JPG'

.\exiftool.exe -GPSLatitude*=$lat -GPSLongitude*=$lon $fileName '-overwrite_original_in_place'

I've gone through numerous attempts with single/backtick/double quotes, trying to concatenate and anything else I can think of - but that magic format hasn't appeared!

Any thoughts on what I am doing wrong?

As an example I thought this was really work, yet didn't. But it matches up with the command that does when it's hard coded. enter image description here

EDIT/Update - The * are required inside the command, otherwise it doesn't work. They are used to get around not passing in reference locators. If you were to run these commands in PS, then these are the errors that you get.

cmd -> .\exiftool.exe "-GPSLatitude*=$lat" "-GPSLongtitude*=$lon" $FileName

error ->

No Error, but the file does not get any GPS tags. Nothing actually modified.

cmd ->

$combLat = "`'-GPSLatitude*=$lat`'" # + "
$combLon = "`'-GPSLongitude*=$lon`'" # + "'"
$combined = "$combLat $combLon $fileName"
# $combined will output the following: '-GPSLatitude*=-3.4651045874' '-GPSLongitude*=55.9359839838' 'E:\CameraAddGPS\TestFolder\DSC01010.JPG' 

.\exiftool.exe $combined

error ->

.\exiftool.exe : Wildcards don't work in the directory specification
At E:\CameraAddGPS\TestFolder\demo.ps1:25 char:1
+ .\exiftool.exe $combined
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Wildcards don't...y specification:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
No matching files

Update 2 - This will work, but I do not want to update the image twice.

 $combLat = '-GPSLatitude*=' + $lat
 $combLon = '-GPSLongitude*=' + $lon

 .\exiftool.exe $combLat $fileName '-overwrite_original_in_place'
 .\exiftool.exe $combLon $fileName '-overwrite_original_in_place'
3
  • 1
    Please update your minimal reproducible example (pictures are mostly unwelcome). Commented Apr 16, 2021 at 20:40
  • You missed to share most important detail which is the error message that you're getting. what means -GPSLatitude*? I think you need to specify full option name without wildcards and without = (equal sign) example: -GPSLatitude $lat Commented Apr 16, 2021 at 20:40
  • Updated it, with some examples. You would need the exiftool to run the samples though. The wildcards and = are most definitely required in the command otherwise they fail. As an side if I break the command into two then I can get it to work. Code in comments doesn't work. Will update Q again. Commented Apr 16, 2021 at 21:30

1 Answer 1

2

The problem is that the latitude and longtitude argumets are "attached" directly to the -GPSLatitute* and -GPSLongtitude* parameter names after the = sign. (The - initial character prevents PowerShell from invoking variable expansion - see GitHub issue #14587.)

One way to work around this is to wrap the -GPSLatitude* and -GPSLongtitude* parameters in " quotes; e.g.

.\exiftool.exe "-GPSLatitude*=$lat" "-GPSLongtitude*=$lon" $FileName -overwrite_original_in_place

Another way is to prefix the - character with a backquote (`); e.g.:

.\exiftool.exe `-GPSLatitude*=$lat `-GPSLongitude*=$lon $fileName -overwrite_original_in_place

I prefer the first variation as it seems more readable to me.

Aside #1: There's no need for the single ' quotes around that last parameter. They don't hurt, but they don't do anything, either.

Aside #2: You can see the actual command line that PowerShell is running if you prefix your command with the getargs command available here:

https://github.com/Bill-Stewart/getargs/releases

The getargs utility outputs the actual command line without any parsing or interpretation and will show the actual command that PowerShell will run.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but that is not the answer. As @mklement0 as pointed out the - may well be the issue. I've updated the Q with more info if that helps. As in if I split the command into two then I can get it to work. But updating the file twice seems very wrong.
Close. You lead me to getting it though (again). In your example you missed the *. Stick that in and it works. What was really stupid of me was I spend so long trying out various connotations I mixed up the lat/lon when passing in. So when it updated and placed it into the Seychelles I thought it was just another reference error - it was my error...! That took me way to long, cheers.
Went to edit this answer to add in the *, but it wouldn't let me. Add them in and I'll tick for a great answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.