Get Users Photo from Office 365 (Get-UserPhoto)

Thanks jrv, however, doesn't that last method get the thumbnailphoto from the AD account? Sadly, we have the photo only stored in Office 365 and not sync'd back to AD.

Or should I be doing;

$user = Get-UserPhoto user@domain.com
$user.thumbnailphoto | Set-Content "C:\Export\Photo$($user.Identity).jpg" -Encoding byte

Actually, looking at the methods for Get-UserPhoto, there is one called "PictureData" which is a Byte type. So I guess this might be better;

$user = Get-UserPhoto user@domain.com
$user.PictureData |Set-Content "C:\Export\Photo$($user.Identity).jpg" -Encoding byte

Just tested this and, IT WORKS!

Thanks for putting me on the right track jrv.
  • Edited by Robin F Herbert Wednesday, November 12, 2014 12:49 PM update with thanks message
  • Marked as answer by Robin F Herbert Friday, January 09, 2015 12:21 PM
November 12th, 2014 12:48pm

Thanks jrv, however, doesn't that last method get the thumbnailphoto from the AD account? Sadly, we have the photo only stored in Office 365 and not sync'd back to AD.

Or should I be doing;

$user = Get-UserPhoto user@domain.com
$user.thumbnailphoto | Set-Content "C:\Export\Photo$($user.Identity).jpg" -Encoding byte

Actually, looking at the methods for Get-UserPhoto, there is one called "PictureData" which is a Byte type. So I guess this might be better;

$user = Get-UserPhoto user@domain.com
$user.PictureData |Set-Content "C:\Export\Photo$($user.Identity).jpg" -Encoding byte

Just tested this and, IT WORKS!

Thanks for putting me on the right track jrv.
  • Edited by Robin F Herbert Wednesday, November 12, 2014 12:49 PM update with thanks message
  • Marked as answer by Robin F Herbert Friday, January 09, 2015 12:21 PM
Free Windows Admin Tool Kit Click here and download it now
November 12th, 2014 3:48pm

If  you get the user object this should work:
$user.thumbnailphoto |
    Set-Content "c:\ADexport\Photos$($User.samaccountname).jpg" -Encoding byte
November 13th, 2014 6:47am

Thanks jrv, however, doesn't that last method get the thumbnailphoto from the AD account? Sadly, we have the photo only stored in Office 365 and not sync'd back to AD.

Or should I be doing;

$user = Get-UserPhoto user@domain.com
$user.thumbnailphoto | Set-Content "C:\Export\Photo$($user.Identity).jpg" -Encoding byte

Actually, looking at the methods for Get-UserPhoto, there is one called "PictureData" which is a Byte type. So I guess this might be better;

$user = Get-UserPhoto user@domain.com
$user.PictureData |Set-Content "C:\Export\Photo$($user.Identity).jpg" -Encoding byte

Just tested this and, IT WORKS!

Thanks for putting me on the right track jrv.
  • Edited by Robin F Herbert 22 hours 43 minutes ago update with thanks message
Free Windows Admin Tool Kit Click here and download it now
November 13th, 2014 7:56am

Get-UserPhoto says it returns a user object.  Have you tried it?

November 13th, 2014 7:59am

Hi all,

I can use Get-UserPhoto cmdlet to find out about a users' photo (via msonline module etc.), but how (if at all) can I use it to actually retrieve the photo itself?

And, if I can't use this cmdlet, how else could I script it for a user to retrieve their own photo from Office 365?

(What I'd like to do is to use that photo as the Windows 8(.1) account picture, which people have written simple scripts for already IF that photo comes from AD. e.g., http://blog.jourdant.me/ps-setting-windows-8-account-picture-from-ad/)

Many thanks!

Robin

Free Windows Admin Tool Kit Click here and download it now
November 14th, 2014 5:36am

Try this:

http://msdn.microsoft.com/en-us/library/office/jj900502(v=exchg.150).aspx

November 14th, 2014 6:16am

So, in your experience, the powershell command cannot be used to retrieve a users photo from Office 365, but the SOAP method does allow you to do so?

(Or did you just put a link you just googled for?)

Sadly, my skills with SOAP are rather limited; how would you tie this into a VB or Powershell script?

Free Windows Admin Tool Kit Click here and download it now
November 14th, 2014 6:30am

We would use the EWS library for PowerShell or use New-WebProxy to handle all of the soap stuff.

The Get-UserPhoto returns a user object which has a thumbnail property.  You can save that as a byte array to a file with a jpg extension.  Look in the repository for examples.

November 14th, 2014 6:34am

Any idea how to determine if a user has a user photo uploaded?  I can do this:

$userphoto=get-userphoto user@domain.com

and then check for $userphoto -eq null  , but when I do that, if the user has no photo the get-userphoto throws an error and takes quite awhile (5-10 seconds) to return. I was hoping there might be a faster way, since I have 15K user accounts to check.

Thanks.

Free Windows Admin Tool Kit Click here and download it now
February 4th, 2015 1:37pm

if($userphoto=get-userphoto user@domain.com -ea 0){

      'get a user phot'

}else{

    'no user photo'

February 4th, 2015 1:44pm

Hi,

Know this post has already been answered but it helped me with what I needed to do.  I wanted to download all user photos from O365 and came up with the following one-liner

get-mailbox | % {Get-UserPhoto $_.identity} | % {Set-Content -path "C:\temp\$($_.identity).jpg" -value $_.picturedata -Encoding byte}

Hopefully it might come in useful for someone.

Steve.


Free Windows Admin Tool Kit Click here and download it now
June 28th, 2015 10:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics