PowerShell script to read metadata info from pictures

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Mohan Derebail Mohan Derebail 1 year, 9 months ago.

  • Author
    Posts
  • #31143
    Profile photo of Mohan Derebail
    Mohan Derebail
    Participant

    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

  • #31147
    Profile photo of Cyril Muffat
    Cyril Muffat
    Participant

    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" 
    

    2. 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

    3. 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.

  • #31290
    Profile photo of Mohan Derebail
    Mohan Derebail
    Participant

    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"

  • #31303
    Profile photo of Mohan Derebail
    Mohan Derebail
    Participant

    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.

You must be logged in to reply to this topic.