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:
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.
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.
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.
2.Connect-EXOPSSession has a parameter UserPrincipalName. You can use Connect-EXOPSSession, with or without UserPrincipalName. For eg,
1 | Connect-EXOPSSession -UserPrincipalName Admin@Contoso.com |
3.Enter the password in the sign-in window and then click Sign in.
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.
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.
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,