Help With PowerShell To Get Image Pixel Dimensions - Almost There

I have an external drive that has a bunch of photos in folders. They are all image types (bmp, jpg, jpeg, png, pcx, tif, gif, etc.)

In PowerShell, DOS batch(CMD), Excel VBA or VB Script I need a script that can recursively go from the root and find each image and IF it has pixel dimensions, I need it to write the Path, FileName (or Path\FileName together) and then pipe, comma or tab delimited, list the Width, Height (or Width x Height).

So the output for example would be:

H:\My Photos\1998\JohnK.png|1024|768

something like that. I can work with different delimiters and and even handle the dimensions in 1024x768 format.

I found maybe 5 examples online for various languages and none of them worked.

This PowerShell script below ran for 2 hours from the root and I thought it worked but it never created an output file. I then ran it on 1 folder and it took a second to run and it created the output file but the file was blank.

param( $folder = "H:\", $outputFile = "D:\Desktop\imagedetails.txt" )
$objShell = New-Object -ComObject Shell.Application
$fileList = @()
$attrList = @{}
$details = ( "Dimensions" )
$objFolder = $objShell.namespace($folder)
for ($attr = 0 ; $attr  -le 500; $attr++)
    $attrName = $objFolder.getDetailsOf($objFolder.items, $attr)
    if ( $attrName -and ( -not $attrList.Contains($attrName) ))
        $attrList.add( $attrName, $attr )
dir $folder -Recurse -Directory | ForEach-Object{
    $objFolder = $objShell.namespace($_.FullName)
    foreach($file in $objFolder.items())
        foreach( $attr in $details)
            $attrValue = $objFolder.getDetailsOf($file, $attrList[$attr])
            if ( $attrValue )
                Add-Member -InputObject $file -MemberType NoteProperty -Name $("A_" + $attr) -value $attrValue
        $fileList += $file
$fileList | Export-Csv $outputFile -Delimiter ','
$fileList | Format-Table

Any help would be appreciated.

If it will help to know WHY I need this, I can tell you exactly what I am doing. I ran the program AllDup against this drive and it found 84,000+ duplicate groups and when I click each group the program worked great. It found all the smaller versions of photos that I no longer want. I just want the larger originals.

I exported AllDup’s results to Excel and it’s great except it does not export the dimensions. Believe it or not larger dimension size does not always mean larger file size I found out. Plus you cannot go by larger file size alone to determine the best photo.

I am fairly experienced in Excel VBA (not enough to get the image dimensions off all images recursively though or even just the Dimensions of those files using a path/file list which I have.). I need the dimensions to add them to my Results spreadsheet for each image.

In AllDup, if I do it manually, in each Duplicate Group I first take the image(s) that have the largest dimensions. Then if there are 2 with the same largest dimension size, I choose to keep just the one of these 2 with the largest file size. The Export file does have the File Size. I just need to add the dimensions and I can write the VBA macro to automated the rest.

I do not want to click on and manually choose and back-up 84,000+ groups of images.

Before anyone recommends DupeGuru, do NOT use that program if you value your photos. I lost the only copies of many photos using this thinking I was keeping only the best version.

I DO however recommend the program DropIt for organizing photos by Date Taken, Camera Make and Model, etc. It will save you a lot of time.

So far AllDup is meeting my needs EXCEPT for exporting image Dimensions.


even according to the comment to the SuperUser post you’ve got this script from this script is not working. :man_shrugging:t3:

It is not the scope of this forum to debug scripts you’ve found on the internet. You could try to contact the author of the script and ask for help though.

Regardless of that … how would a list like this …

… help you determine what images to keep and what to remove? :man_shrugging:t3:

That’s fine. I will keep searching and posting on other forums until I find a solution that works. This code came from a very old post. The thread is locked. I will try to reach out to them if they are still a member. There is probably a better and faster language to do this in than PowerShell. It seems every time I post here I never get assistance, just many reasons why I cannot use PowerShell for what I am doing. I have watched many PowerShell YouTube videos and they make it sound like a great way to automate things, but I feel maybe Linux or Command Prompt might be a better way.

Thanks anyway.

We provide assistance with those who have ran into an issue with code they’ve been writing. Your request is not for assistance, but either to figure out why this script you found won’t do what you would like, or to write a script for you (in one of several different languages you specified) typically what your circumstance calls for is either A) you spend some time debugging this or writing your own script, using forums such as these for specific issues encountered during the endeavor or B) you hire someone to build what you desire.

1 Like

I’ll give you a hint.


Thanks neemobeer ( we all need more beer :slight_smile: ) … from what you posted, I played a bit and it was very easy to get the image properties. Good stuff to know, thanks…

Perfect. That helped me figure it out and I got it to work. I realize others may have been trying to teach me PowerShell and it’s a good goal for some, but I have to focus on getting the hundreds of thousands of family photos on my Synergy NAS. I spent a lot of years scanning and collecting digital family photos and do not have a ton of time left, but I want to get this done so my family and future generations in my family can enjoy family photos and home movies. I don’t even know who in my family would take over this task. I was a VB 6 and PICK BASIC developer for years and I need to now automate everything I can to get this done while I still can. I really wish I had much more time to learn new languages but everyone has different needs and goals. Not complaining, this is just my situation. Thanks again and this worked flawlessly.

Great that you’ve found a solution. :+1:t3: How about sharing it with the world. That could help others looking for a solution to the same or a similar issue.

Get-ChildItem -Recurse H:\ -Filter *.jpg | % {
    $image = [System.Drawing.Image]::FromFile($_.FullName)
        New-Object PSObject -Property @{
            fullname = $_.Fullname
            width = $image.Width
            height = $image.Height

} | Export-Csv 'C:\jpglog.csv' -NoTypeInformation

Change the *.jpg in the first line to anything image file format. I know there is a way to just include all the filetypes but this runs so fast, I just changed the name of the Export log file for each File Type and ran it for each and concatenated these csv files together at the end.

It really worked well for my purpose.

1 Like


And thanks for sharing. :+1:t3:

Change -Filter to -Include "*.jpg","*.png","*.bmp" etc