none
Get Users Photo from Office 365 (Get-UserPhoto) RRS feed

  • Question

  • 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

    Wednesday, November 12, 2014 10:30 AM

Answers

  • 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 9, 2015 12:21 PM
    Wednesday, November 12, 2014 12:48 PM
  • 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.


    ¯\_(ツ)_/¯

    Wednesday, November 12, 2014 11:29 AM

All replies

  • 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?

    Wednesday, November 12, 2014 11:24 AM
  • 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.


    ¯\_(ツ)_/¯

    Wednesday, November 12, 2014 11:29 AM
  • If  you get the user object this should work:
    $user.thumbnailphoto |
        Set-Content "c:\ADexport\Photos$($User.samaccountname).jpg" -Encoding byte

    ¯\_(ツ)_/¯

    Wednesday, November 12, 2014 11:39 AM
  • 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 9, 2015 12:21 PM
    Wednesday, November 12, 2014 12:48 PM
  • Get-UserPhoto says it returns a user object.  Have you tried it?


    ¯\_(ツ)_/¯

    Wednesday, November 12, 2014 12:51 PM
  • 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.

    Wednesday, February 4, 2015 6:35 PM
  • if($userphoto=get-userphoto user@domain.com -ea 0){

          'get a user phot'

    }else{

        'no user photo'


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, February 4, 2015 6:43 PM
    Wednesday, February 4, 2015 6:42 PM
  • 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.



    Just a good old boy, never meaning no harm

    Monday, June 29, 2015 2:09 AM
  • Steve, this script works well. 

    1. is it possible to save the photo with the userprincipalname.jpg? 

    2. Can you script filter users who do not have a photo?

    Saturday, October 31, 2015 1:03 AM
  • I'm using this to get a list of only accounts with photos. Much quicker than trying Get-Photo on every account.

    Get-Mailbox -ResultSize unlimited | Where-Object HasPicture -eq $true

    Then I use Get-Photo with the results.

    Sunday, November 15, 2015 1:36 AM
  • I used the following command to avoid powershell error and to export only foto for the users that have a photo

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

    • Proposed as answer by Blacksuit1 Friday, April 28, 2017 8:05 PM
    Monday, May 9, 2016 4:32 PM
  • get-mailbox | ?{$_.HasPicture} | Get-UserPhoto |
         % {Set-Content -path "C:\temp\$($_.identity).jpg" -value $_.picturedata -Encoding byte}


    \_(ツ)_/

    Monday, May 9, 2016 4:48 PM