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.