Compartilhar via


Microsoft Office 365–Using Exchange PowerShell to get Users photo from Microsoft Office 365

You can use the Get-UserPhoto cmdlet to view information about the user photos feature that allows users to associate a picture with their account. User photos appear in on-premises and cloud-based client applications, such as Microsoft Outlook Web App (OWA), Lync, Skype for Business, and SharePoint.

Please note that,

- This cmdlet is available in Exchange Online & Exchange Server 2016.
- The user photos feature allows users to associate a picture with their account.
- User photos are stored in the user's Active Directory account and in the root directory of the user's Exchange mailbox.
- The user photo feature must be set for a user before you can run the Get-UserPhoto cmdlet to view information about the user's photo. Otherwise, you get an error message saying the user photo doesn't exist for the specified users.
- Administrators use the Set-UserPhoto cmdlet or the Exchange admin center (EAC) to configure user photos. Alternately the users can upload, preview, and save a user photo to their account by using the Outlook on the web Options page.

So let we play with this cmdlet:

PS C:\WINDOWS\system32> Get-UserPhoto "deva@xxx.onmicrosoft.com"

RunspaceId  : 7adbbe2f-e5eb-4156-b8ed-2b0d5e9140fb

Identity    : deva

PictureData : {255, 216, 255, 224...}

Thumbprint  : -2069673794

IsValid     : True

ObjectState : New

It gets you the User photo info.

Let me tweak it a bit – as the requirement is to get all the user photo from Office 365.

PS C:\WINDOWS\system32> get-mailbox | % {Get-UserPhoto $_.identity} | % {Set-Content -path "d:\export\$($_.identity).jpg
" -value $_.picturedata -Encoding byte}

Once the above powershell works, then let me look at the path that we set it above. The folder path will contain the users photo from Office 365 user’s Exchange mailbox/AD.

image

Hope this helps.