I have many JPG files named like IMG_xxxx.jpg and want to rename them using the format yyyymmdd_IMG_xxxx.jpg. My current command uses LastWriteTime, but that timestamp is inaccurate because the files have been copied and moved several times. The correct date is stored in the EXIF Date Taken field. All files are in the current folder, have Date Taken metadata, and should be renamed in place. What is the simplest PowerShell command or function to read the EXIF date and use it as the filename prefix?
2 Answers
You can read the EXIF Date Taken value with .NET's System.Drawing classes. EXIF tag 36867 is DateTimeOriginal, which is usually the actual date and time the photo was taken. This example formats it as yyyyMMdd and renames the files in the current directory:
```powershell
Add-Type -AssemblyName System.Drawing
Get-ChildItem -File -Filter '*.jpg' | ForEach-Object {
$file = $_
$image = $null
try {
$image = [System.Drawing.Image]::FromFile($file.FullName)
$property = $image.GetPropertyItem(36867)
$taken = [System.Text.Encoding]::ASCII.GetString($property.Value).Trim([char]0)
$date = [datetime]::ParseExact($taken, 'yyyy:MM:dd HH:mm:ss', $null)
$newName = $date.ToString('yyyyMMdd_') + $file.Name
if ($newName -ne $file.Name) {
Rename-Item -LiteralPath $file.FullName -NewName $newName
}
}
catch {
Write-Warning "Could not read EXIF data from $($file.Name): $($_.Exception.Message)"
}
finally {
if ($image) { $image.Dispose() }
}
}
```
The `Dispose()` call is important because it releases the image file before the rename happens. Test on copies first, especially if a destination filename might already exist.
`GetDetailsOf` is not a built-in PowerShell cmdlet. It is generally accessed through the Windows Shell COM object, so calling it directly will produce the “term is not recognized” error. You could use the Shell object, but it is less reliable because the property index and returned value can vary by Windows version and folder type. For consistent EXIF handling, an EXIF-aware utility such as ExifTool is usually the safer option, especially when some images may be missing metadata or use different date fields.
That explains the error I was seeing. I was treating `GetDetailsOf` as though it were a native cmdlet, so I’ll use an EXIF reader instead of substituting it directly into `Rename-Item`.

The EXIF value normally looks like `2020:07:18 14:32:10`, so parsing it with `ParseExact` avoids relying on the computer's regional date settings.