PowerShell and Image Meta information (even RAW)

Several years ago I developed a DOS Batch script that would make double-copies of images off flash media (for loss protection) and then file them to specific directories based on Year-Month-Day as well as prepending the camera model* to the file to ensure the filenames were unique.  I was thinking of converting to PowerShell since there is a lot more capability there than Ye Olde DOS prompt.

First step, how do I get Meta data information from a raw camera file into PowerShell?

Well, a little reading and experimentation, and it becomes a rather short one-liner.  This example uses the file 5D_IMG_9027.CR2 and assumes ExifTool is installed in the local directory:

$meta=([xml](.\exiftool.exe .\5D_IMG_9027.CR2 -X)).rdf.description

Here’s an example of some of the attributes after processing:

PS C:\pics> $meta=([xml](.\exiftool.exe .\5D_IMG_9027.CR2 -X)).rdf.description
PS C:\pics> $meta | fl ISO,CanonModel,Lens,Aperture,ShutterSpeed

ISO          : {100, 100, 100}
CanonModel   : 5D
Lens         : 85.0 mm
Aperture     : 1.8
ShutterSpeed : 1/25

Now that is pretty awesome!

Note: If you’re looking to do this for a large number of files, I recommend using ExifTool’s batch mode and doing the conversion from XML once, instead of once for each file.

*This is actually accomplished with a bit of ExifTool programming… place this file in the same directory and it “exposes” a new variable called CanonModel:

# .ExifTool_config
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        CanonModel => {
            Require => {
                0 => 'Model',
            ValueConv => 'length($val[0]) > 4 ? substr($val[0], rindex($val[0]," ")+1, 100) : undef',

P.S. If you’re looking for less information than what ExifTool can provide, you can look into “new-object -com shell.application” or “[System.Windows.Media.Imaging.BitmapFrame]” but neither of those had the detail nor capability on CR2 or other raw files.

This entry was posted in Uncategorized. Bookmark the permalink.