# PowerShell script to read metadata info from pictures

**URL:** <https://forums.powershell.org/t/powershell-script-to-read-metadata-info-from-pictures/5074>\
**Category:** PowerShell Help\
**Created:** [October 21, 2015, 9:17pm UTC](https://forums.powershell.org/t/powershell-script-to-read-metadata-info-from-pictures/5074 "2015-10-21T21:17:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohan-derebail](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@mohan-derebail](https://forums.powershell.org/u/mohan-derebail)\
**Post date:** [October 21, 2015, 9:17pm UTC](https://forums.powershell.org/t/powershell-script-to-read-metadata-info-from-pictures/5074/1 "2015-10-21T21:17:13Z")

</div>

Hi Guys,

I’m new to powershell scripts. I need a help with the below code:

`
Function Get-FileMetaData 
{ 
Param([string]$folder)
foreach($sFolder in $folder)
{
$a = 0
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.namespace($sFolder)
foreach ($File in $objFolder.items())
{
$FileMetaData = New-Object PSOBJECT
for ($a ; $a -le 266; $a++)
{
if($objFolder.getDetailsOf($File, $a))
{
$hash += @{$($objFolder.getDetailsOf($objFolder.items, $a)) =
$($objFolder.getDetailsOf($File, $a)) }
$FileMetaData | Add-Member $hash
$hash.clear()
} #end if
} #end for
$a=0
$FileMetaData
} #end foreach $file
} #end foreach $sfolder
} #end Get-FileMetaData
$picdata = Get-FileMetaData -Folder ‘C:\Users\mohad\Desktop\Shell\image’ | select name, Dimensions, size, width, height
$picdata
`

My need is below:

1. I’m converting this code into exe, so the script should give info abt all the images from the folder in which it is started (the folder will always be named as “images” )
2. The result should be stored in a csv file name as “image data”.
3. I want to extract additional info such as "horizontal/vertical resolution’ of an image, color representation etc.

please help me!! TIA

---

<div class="post-metadata">

**Author:** ![cyril-muffat](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@cyril-muffat](https://forums.powershell.org/u/cyril-muffat)\
**Post date:** [October 21, 2015, 10:23pm UTC](https://forums.powershell.org/t/powershell-script-to-read-metadata-info-from-pictures/5074/2 "2015-10-21T22:23:33Z")

</div>

1. I’m converting this code into exe, so the script should give info abt all the images from the folder in which it is started (the folder will always be named as “images” )

edit:

```
$path = get-location
Get-FileMetaData -Folder "$path\images"
```

1. The result should be stored in a csv file name as “image data”.

ex :

```
Get-FileMetaData -Folder $env:USERPROFILE\Pictures\test\ | convertto-csv -Delimiter ";" -NoTypeInformation | Out-File $env:USERPROFILE\desktop\test.csv
```

1. I want to extract additional info such as "horizontal/vertical resolution’ of an image, color representation etc.

just select witch tag you want to extract but if you are looking for something that isn’t in metadata you will have to generate it with a function.

---

<div class="post-metadata">

**Author:** ![mohan-derebail](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@mohan-derebail](https://forums.powershell.org/u/mohan-derebail)\
**Post date:** [October 23, 2015, 5:57pm UTC](https://forums.powershell.org/t/powershell-script-to-read-metadata-info-from-pictures/5074/3 "2015-10-23T17:57:30Z")

</div>

Thanks for the support cyril !

Before I explain more, the exe which i’m going to create will be used across multiple systems, where the “userprofile” name will differ. So how to handle that?

And where should I add this below code and what should i remove ?  
`$path = get-location
Get-FileMetaData -Folder “$path\images”`

---

<div class="post-metadata">

**Author:** ![mohan-derebail](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@mohan-derebail](https://forums.powershell.org/u/mohan-derebail)\
**Post date:** [October 25, 2015, 3:04pm UTC](https://forums.powershell.org/t/powershell-script-to-read-metadata-info-from-pictures/5074/4 "2015-10-25T15:04:26Z")

</div>

I tried the below code:  
`
Function Get-FileMetaData
{`

`
Param([string]$folder)
foreach($sFolder in $folder)
{
$a = 0
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.namespace($sFolder)
foreach ($File in $objFolder.items())
{
$FileMetaData = New-Object PSOBJECT
for ($a ; $a -le 266; $a++)
{
if($objFolder.getDetailsOf($File, $a))
{
$hash += @{$($objFolder.getDetailsOf($objFolder.items, $a)) =
$($objFolder.getDetailsOf($File, $a)) }
$FileMetaData | Add-Member $hash
$hash.clear()
} #end if
} #end for
$a=0
$FileMetaData
} #end foreach $file
} #end foreach $sfolder
} #end Get-FileMetaData
`

`$path = get-location
Get-FileMetaData -Folder “$path\images” -Folder “$path\images”| select name, Dimensions, size, width, height
$picdata
Get-FileMetaData -Folder $env:USERPROFILE\Desktop\Shell\image | convertto-csv | Out-File $env:USERPROFILE\Desktop\Shell\image\power.csv`

The output format in the csv is totally lost:

Name,“Size”,“Item type”,“Date modified”,“Date created”,“Date accessed”,“Attributes”,“Perceived type”,“Owner”,“Kind”,“Rating”,“Dimensions”,“Computer”,“Filename”,“Bit depth”,“Horizontal resolution”,“Width”,“Vertical resolution”,“Height”,“Shared”,“Folder name”,“Folder path”,“Folder”,“Path”,“Type”,“Link status”

B00A5MRG6O\_handwritten notes.jpg,“61.8 KB”,“JPEG image”,“8/7/2015 7:23 AM”,“10/22/2015 4:39 PM”,“10/22/2015 4:39 PM”,“A”,“Image”,“ANT\mohad”,“Picture”,“Unrated”,“‪249 x 330‬”,“MAA-PB96KHX (this computer)”,“B00A5MRG6O\_handwritten notes.jpg”,“8”,“‎120 dpi”,“‎249 pixels”,“‎120 dpi”,“‎330 pixels”,“No”,“image”,“C:\Users\mohad\Desktop\Shell\image”,“image (C:\Users\mohad\Desktop\Shell)”,“C:\Users\mohad\Desktop\Shell\image\B00A5MRG6O\_handwritten notes.jpg”,“JPEG image”,“Unresolved”

I just need the image name, type, dimension, size . Where name should be in the row and " type, dimension, size " should be the column.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:44pm UTC](https://forums.powershell.org/t/powershell-script-to-read-metadata-info-from-pictures/5074/5 "2024-05-16T20:44:33Z")

</div>


