network technician/administrator/manager blog
Download O365 user photos
Download O365 user photos

Download O365 user photos

In this quick article ill show you how to download all office 365 user profile photos

First lets connect to O365 Exchange Online:

Step1: Install Exchange Online PowerShell Module for MFA

The first thing you need to do is download the Exchange Online Remote PowerShell module.To download Exchange Online PowerShell Module directly, you can use this quick link: 

https://cmdletpswmodule.blob.core.windows.net/exopsmodule/Microsoft.Online.CSE.PSModule.Client.application 

Alternatively, to download the Exchange Online MFA module through Microsoft, follow the below steps.

1.Login to Exchange Admin Center using Internet Explorer or Edge. Has to be one of them, Chrome, Firefox… wont work.

2.In the EAC, go to Hybridand click the Configure button (as mentioned in below image) to download the Exchange Online PowerShell Module for MFA.

Exchange Online Powershell module supports MFA

Note: A browser that uses ClickOnce to download (like IE or Edge) is needed to download otherwise you will get an error during installation. Click Connect-ExoPSSession troubleshooting tips for more troubleshooting tips.

3.Click Install.

Exchange Online Remote PowerShell installation

Step2: Connect Exchange Online PowerShell Using MFA

1.Connect-EXOPSSession used to connect to Exchange Online with MFA. You can’t use Connect-EXOPSSession in standard Windows PowerShell. You need to launch Exchange Online Remote PowerShell module. When you launch the Exchange Online Remote PowerShell module, a tip about the usage is shown.

Exchange online Remote PowerShell Module

2.Connect-EXOPSSession has a parameter UserPrincipalName. You can use Connect-EXOPSSession, with or without UserPrincipalName. For eg,

1Connect-EXOPSSession -UserPrincipalName Admin@Contoso.com

3.Enter the password in the sign-in window and then click Sign in.

Microsoft Exchange Online Remote PowerShell login

4. A verification code generated and delivered based on MFA configured for your account. Enter the verification code in the verification window and then click Sign in.

Microsoft Exchange Online Powershell login with MFA

5. After step 4, the Exchange online cmdlets are imported into Exchange Online remote PowerShell Module session. If you don’t receive any errors, you connected successfully as shown in the below figure.

Connect Exchange online using MFA

Now that your connected to Exchange Online we need to user PowerShell to find and download all the user profile pictures.

Copy and paste the code below into notepad, you might need to update a line to suit your environment.

#Input Parameters:
$folderpath="C:\temp\AllUserProfilePictures\" 

#Download all user profile pictures from Office 365:
New-Item -ItemType directory -Path $folderpath –force 
$allUsers=Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited|select UserPrincipalName,Alias
Foreach($user in $allUsers)
{
$path=$folderpath+$user.Alias+".Jpg"
$photo=Get-Userphoto -identity $user.UserPrincipalName -ErrorAction SilentlyContinue
If($photo.PictureData -ne $null)
{
[io.file]::WriteAllBytes($path,$photo.PictureData)
Write-Host $user.Alias “profile picture downloaded”
}
}     

You may wish to update the $folderpath from “C:\temp\AllUserProfilePictures\” to a location best suited to you.

Once updated, simply paste it into your Exchange PowerShell window. The script will start downloading the images.

Job done.

Thank you,