Omar and I were chatting today and he wanted to to know how to access EXIF data from PowerShell. Omar wrote a nice little photo library a while back that extracts and interprets EXIF data from images. The .NET Framework 2.0 has some support for EXIF, but it doesn't attempt to interpret it.
Anyway, Omar wants to do some manipulation of his files, doing renaming and such, based on the EXIF data. He wanted to sort a directory by the date the format was actually TAKEN - this is stored inside the photo itself if the time is right on your camera - not the File System Dates.
We could write scripts to manipulate the files his library directly, but wouldn't it be very integrated with the whole PowerShell experience, now would it?
So, here's what we did:
This is one of the most powerful aspect of PowerShell. Actually "spot-welding" new properties on to existing objects. Not object inheritance, mind you, "super-gluing." Like it or hate it, like super-glue, you have to respect that it solves problems.
Now we can do this from our PowerShell:
PS C:\Documents and Settings\shanselm\Desktop> dir *.jpg | sort -desc DatePhotoTaken | select Name, LastWriteTime, DatePhotoTaken
Name LastWriteTime DatePhotoTaken---- ------------- --------------Zenzo Q. at house Jan 1... 1/19/2006 4:26:00 PM 1/18/2006 8:01:00 AMdadandscott.jpg 9/7/2006 2:37:32 PM 2/3/2002 2:57:03 PM
Since we're using Omar's library, we can do whatever we like with any the other EXIF details he expose:
PS C:\Documents and Settings\shanselm\Desktop>$photo = new-object PhotoLibrary.Photo ((get-item dadandscott.jpg).Fullname)
PS C:\Documents and Settings\shanselm\Desktop>$photo | select make, model, Width, Height, DateTimeOriginal | format-list
Make : Eastman Kodak CompanyModel : KODAK DC265 ZOOM DIGITAL CAMERA (V01.00)Width : 1536Height : 1024DateTimeOriginal : 2/3/2002 2:57:03 PM
Shiny.
Ads by The Lounge