How to search for photo files using camera model in PowerShell

PUSHKAR DIGHE 20 Reputation points
2024-11-27T16:07:55.4866667+00:00

I need to find if files taken by a certain camera have been backed up to my photos library. There are 1000s of photos in the library taken by multiple cameras and I need to build a PowerShell script to find all those photos taken by a specific camera model

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,667 questions
{count} votes

Accepted answer
  1. MotoX80 34,686 Reputation points
    2024-11-27T19:35:03.3466667+00:00

    Here is script that looks through a folder structure and outputs the model both to the console and to a csv file. Modify it to suit your needs.

    $folder = 'c:\multimedia\pictures\2010'
    cls
    $shell = New-Object -COMObject Shell.Application
    $files = Get-ChildItem -Path $folder -File -recurse 
    $pics = @()
    foreach ($f in $files) {
        $model = "" 
        $shellfolder = $shell.Namespace($f.Directory.FullName)
        $shellfile = $shellfolder.ParseName($f.name)
        # To find the ID of the extended attribute you're interested in:
        0..50 | ForEach-Object {
            $prop = $shellfolder.GetDetailsOf($null, $_)
            $propvalue = $shellfolder.GetDetailsOf($shellfile, $_)
           
            if ($prop -eq "Camera model") {
                $model = $propvalue
            }             
        }
        $pics += [PSCustomObject]@{
            Model = $model
            Picture = $f.FullName
        }
    }
    $pics    # show all files 
    $pics | Where-Object -Property Model -match "canon"   # show only pics taken by a canon 
    $pics | Export-Csv -Path "C:\temp\report.csv" -NoTypeInformation 
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Paul Wiersma 0 Reputation points
    2024-11-27T17:10:30.38+00:00

    Hi Pushkar,

    The Get-FileMetaData module needs to be built and installed, it does not ship with pwsh, the script repo listed in the blog is no longer in use.

    See this git repo for the script to build and export the module path:

    https://gist.github.com/woehrl01/5f50cb311f3ec711f6c776b2cb09c34e

    Rerun your script from the blog
    https://devblogs.microsoft.com/scripting/use-powershell-to-find-metadata-from-photograph-files/

    $picMetadata = Get-FileMetaData -folder (Get-childitem <YOUR DIRECTORY HERE> -Recurse -Directory).FullName

    You may need to import/install the module.... If it doesn't work relaunch pwsh after the import/install and try again.

    For more info; see this learning page on Modules, specifically the subsections on building/importing/installing.

    https://learn.microsoft.com/en-us/powershell/scripting/developer/module/writing-a-windows-powershell-module?view=powershell-7.4

    Thanks,

    Paul

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.