Question

Dear stackoverflowers,

I have a problem with some files. I would like to search for a specific attribute value of a .jpg file. Specifically the "commentary" field.

I tried it like that:

(Get-ChildItem -file C:\picture.jpg | Select-Object -Property *).attributes

All I receive is this:

Archive

Well, that does not help me. I would like to know, what is in this "Archive". There (or maybe somewhere else?) must be those informations I seek.

(Get-ChildItem -file C:\picture.jpg | Select-Object -Property *)
Attributes        : Archive

Doesn't give me any relevant information besides the one, which I already got.

I guess I should be able to get the needed information with this powershell pack: Technet - EXIF But isn't there any way to easily access this data, with the on-board powershell? (I would like to use it on many different computers)

Thanks in advance!

Was it helpful?

Solution

You can try something like this:

function MakeString
{
  $s=""
    for ($i=0 ; $i -le $args[0].value.length; $i ++) 
    {
        if ( [int][char]$args[0].value[$i] -ne 0 )
        {
        $s = $s + [char]$args[0].value[$i] 
        }
    }    

   $s
}

[void][reflection.assembly]::loadfile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll")

$foo=New-Object -TypeName system.drawing.bitmap -ArgumentList "c:\test_image_with_exif_comment_populated.jpg"

makestring $foo.GetPropertyItem(37510) #37510 is the property ID for exif comment use 40092 for property XPComment

remember that if the property comment is not populated the command $foo.GetPropertyItem(37510) return an error!

or to avoid the error use this function:

    function get-jpgcomment ( [string]$path )
    {
    [void][reflection.assembly]::loadfile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll")
    $foo=New-Object -TypeName system.drawing.bitmap -ArgumentList $path #"c:\Users\baric\Pictures\IMG\b.jpg"

    try
    {
        $a = $foo.GetPropertyItem(37510)
        -join ($a.value | % { if ([int][char]$_ -ne 0) {[char]$_} })    
    }

    catch
    {}
}

call it like this:

get-jpgcomment c:\myimage.jpg

it return $null if the property comment is not populated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top