Alex Rivera | Logout

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

Asked 2011-07-26T17:48:18.813
19

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.

Edit
Report

1 Answer

7

In general, you can access any extended property for a file shown in explorer through the shell GetDetailsOf method. Here's a short example, adapted from another answer:

$file = Get-Item IMG_0386.jpg
$shellObject = New-Object -ComObject Shell.Application
$directoryObject = $shellObject.NameSpace( $file.Directory.FullName )
$fileObject = $directoryObject.ParseName( $file.Name )

$property = 'Date taken'
for(
  $index = 5;
  $directoryObject.GetDetailsOf( $directoryObject.Items, $index ) -ne $property;
  ++$index ) { }

$value = $directoryObject.GetDetailsOf( $fileObject, $index )


However, according to the comments on another question, there is no general-purpose mechanism for setting these properties. The System.Drawing.Bitmap class that EBGreen mentioned will work for images, but I'm afraid I also do not know of a .NET option for video files.

answered 2011-12-24T17:50:27.350

Your Answer