Getting DateTaken Info from Pictures

by Jun 10, 2014

If you'd like to reorganize your picture archive, then here is a piece of code that reads the "DateTaken" information from picture files.

The example uses a system function to find out the MyPictures path, then recursively searches for all files in that folder or its subfolders. The result is piped to Get-DateTaken which returns the picture file name, the folder name, and the date the picture was taken.

function Get-DateTaken
{
  param 
  (
    [Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
    [Alias('FullName')]
    [String]
    $Path
  )
  
  begin
  {
    $shell = New-Object -COMObject Shell.Application
  }
  
  process
  {
  $returnvalue = 1 | Select-Object -Property Name, DateTaken, Folder
    $returnvalue.Name = Split-Path $path -Leaf
    $returnvalue.Folder = Split-Path $path
    $shellfolder = $shell.Namespace($returnvalue.Folder)
    $shellfile = $shellfolder.ParseName($returnvalue.Name)
    $returnvalue.DateTaken = $shellfolder.GetDetailsOf($shellfile, 12)

    $returnvalue
  }
}


$picturePath = [System.Environment]::GetFolderPath('MyPictures')
Get-ChildItem -Path $picturePath -Recurse -ErrorAction SilentlyContinue | 
  Get-DateTaken

Twitter This Tip! ReTweet this Tip!