2

I think I've tried every wrong way, and those few that don't just give ugly error messages write a garbled file that cannot be opened (you can still see the JFIF in it, but the jpeg magic smoke has been lost).

The Stream itself is $contactInfo.Get_Item("Photo"). I think I need to do something like this:

$br = new-object System.IO.BinaryReader $contactInfo.Get_Item("Photo")

But past that, I don't know what to do. I've tried Googling, but I'm not even sure what I'm looking for to be quite honest.

The type of the Stream object is Microsoft.Lync.Model.UCStream.

4
  • What is the type that Get_Item() returns? Execute $contactInfo.Get_Item("Photo").GetType().Fullname. If it is a byte[] then just do this Set-Content photo.jpeg $contactInfo.Get_Item("Photo") -Encoding Byte. Commented Mar 8, 2013 at 17:20
  • @KeithHill I've edited to include that information. Commented Mar 8, 2013 at 17:30
  • Use the Read() method to read until end of stream (-1). Take each int except the last and put it in a PowerShell byte[]. Then use $bytes | Set-Content photo.jpeg -enc byte. Commented Mar 8, 2013 at 19:59
  • @KeithHill Would you mind writing it as an answer with a short snippet? Commented Mar 8, 2013 at 20:04

1 Answer 1

3

I don't have access to this particular type (UCStream) but in general you would write this in PowerShell like so:

$br = new-object io.binaryreader $contactInfo.Get_Item("Photo")
$al = new-object collections.generic.list[byte]
while (($i = $br.Read()) != -1)
{
    $al.Add($i)
}

Set-Content photo.jpeg $al.ToArray() -enc byte
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.