Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get programmatic access to the "Date taken" field of an image or video using powershell?

Tags:

powershell

I'm trying convert a bunch of pictures and videos, but when I convert it to a new format I obviously lose the properties of the original file. I'd like to be able to read the "Date taken" property from the old file and update it on the new one using powershell.

like image 284
JNappi Avatar asked Jul 26 '11 17:07

JNappi


1 Answers

I can't test it right now (don't have any images with XIF data laying around, but I think this should work:

[reflection.assembly]::LoadWithPartialName("System.Drawing")
$pic = New-Object System.Drawing.Bitmap('C:\PATH\TO\SomePic.jpg')
$bitearr = $pic.GetPropertyItem(36867).Value 
$string = [System.Text.Encoding]::ASCII.GetString($bitearr) 
$DateTime = [datetime]::ParseExact($string,"yyyy:MM:dd HH:mm:ss`0",$Null)
$DateTime
like image 132
EBGreen Avatar answered Oct 14 '22 05:10

EBGreen