Author Posts

October 22, 2015 at 2:47 am

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

October 22, 2015 at 3:53 am

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.

October 23, 2015 at 11:27 pm

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"

October 25, 2015 at 8:34 pm

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.