I have a folder full of JPG files named like IMG_xxxx.jpg and want to rename them as yyyymmdd_IMG_xxxx.jpg. My current command uses LastWriteTime, but that reflects when the files were copied or modified rather than when the photos were taken. How can I read the EXIF Date Taken value and use it in a PowerShell rename command? All files are in the current folder, have Date Taken metadata, and should be renamed in place.
2 Answers
GetDetailsOf isn't a built-in PowerShell cmdlet, so that example will fail unless you define it yourself. You can read the EXIF Date Taken tag directly with System.Drawing. EXIF tag 36867 is DateTimeOriginal, and 36868 is DateTimeDigitized. For example:
Add-Type -AssemblyName System.Drawing
Get-ChildItem -Filter '*.jpg' -File | ForEach-Object {
$image = [System.Drawing.Image]::FromFile($_.FullName)
try {
$property = $image.GetPropertyItem(36867)
$taken = [Text.Encoding]::ASCII.GetString($property.Value).Trim([char]0)
$date = [datetime]::ParseExact($taken,'yyyy:MM:dd HH:mm:ss',$null)
Rename-Item -LiteralPath $_.FullName -NewName ($date.ToString('yyyyMMdd_') + $_.Name)
}
finally {
$image.Dispose()
}
}
The try/finally is important because the image file remains locked until the Image object is disposed. In production, it is also worth handling files that lack tag 36867 or checking whether the destination filename already exists.
Changing LastWriteTime to CreationTime won't solve this because both are filesystem timestamps, not the date embedded in the photo's EXIF metadata. CreationTime can also change after files are copied or moved. You need an EXIF reader such as System.Drawing or ExifTool; the property index returned by a shell details API is not automatically available as a PowerShell command named GetDetailsOf.
I tried CreationTime, but it was also wrong because these files have been copied and moved over the years. The EXIF Date Taken value is the one that remains accurate.

ExifTool is another practical option, especially for a large collection or images with inconsistent metadata. It can read DateTimeOriginal and rename files without having to maintain your own EXIF-parsing code.