How do I use ExifTool in PowerShell only when DateTimeOriginal is missing?
Asked 8/21/2025
7 views
2 answers
0
On Windows, I have a folder of image files where some have a valid DateTimeOriginal tag and some do not. For files missing that tag, I want ExifTool to copy the file creation date into DateTimeOriginal and leave the others unchanged.
I tried this in PowerShell:
exiftool -if "not $DateTimeOriginal" "-MWG:DateTimeOriginal<FileCreateDate" -overwrite_original .
ExifTool reports that all files failed the condition. How should this be written in PowerShell?
Originally by KnowItAllWannabe. Source · Licensed CC BY-SA 4.0
KnowItAllWannabe
9mo ago
2 Answers
1
You have to pay attention to the highlighting when using PowerShell. In your command, you would see that $DateTimeOriginal has a different color than the rest of the command. That indicates that it is a PowerShell variable, not an exiftool tag name.
Your command would work on Windows CMD, and it will probably work in PowerShell if you change the double quotes into single quotes.
But because PowerShell has different quoting rules from CMD/Mac/Linux, there are exiftool commands that would work correctly under the other command lines, using double quotes for CMD and single quotes on Mac/Linux, that do not work either way on PowerShell. This Exiftool forum post gives an example of a command that doesn't work on PowerShell no matter what quotes are used.
Originally by StarGeek. Source · Licensed CC BY-SA 4.0
StarGeek
9mo ago
0
Generated from our catalog & community — verify before relying on it.
In PowerShell, $DateTimeOriginal is being interpreted as a PowerShell variable, not an ExifTool tag name. That’s why your condition fails.
Use single quotes so PowerShell passes the text through literally to ExifTool:
exiftool -if 'not $DateTimeOriginal' '-MWG:DateTimeOriginal<FileCreateDate' -overwrite_original .
The same command would work as written with double quotes in Windows CMD, but PowerShell has different quoting rules. A quick clue is syntax highlighting: if $DateTimeOriginal is colored like a PowerShell variable, PowerShell is trying to expand it.
So the fix is mainly about quoting in PowerShell, not the ExifTool logic itself.
UniqueBot
AI9mo ago
Your Answer
Related Questions
How do I make Windows use the correct photo date when the camera date is stored in PictureInfo instead of EXIF?
How can I set video file dates to match their embedded metadata on macOS using ExifTool?
How can I set XMP PreservedFileName only if it is empty using ExifTool?
Can EXIF DateTimeOriginal be treated as UTC if OffsetTimeOriginal is missing?
How can I batch-set scanned photos' EXIF dates from mmddyy folder names with ExifTool on Windows?