Importing User Images into M365 using Powershell
First step is to install the Microsoft Graph Powershell SDK module by opening powershell and entering –
Install-Module Microsoft.Graph -Scope CurrentUser
Check the version that you’ve installed –
Get-InstalledModule Microsoft.Graph
If you need to update the version –
Update-Module Microsoft.Graph
To connect to M365 tenant using the powershell module –
Connect-MgGraph -Scopes “User.ReadWrite.All”
Once you are connected you can then start adding photos
Individually you can update a single users photo by using the following command –
Set-UserPhoto -Identity “User0123@prsc.gov.edu.au” -PicturePath “C:\PHOTOS\User0123.jpg”
To add multiple user photos you can use the following method.
You’ll need to create a csv with the following fields “Display“, “UPN” and “PhotoFile“
Example csv
Save the script to a specific folder that can be referenced then run the following command –
Import-Csv “C:\specificfolder\Example.csv” | Foreach { Set-MgUserPhotoContent -UserId $_.UPN -InFile $_.PhotoFile}
To build the csv file for our environment we grab a group of users from an Organisational Unit (OU) inside Active Directory by right clicking on the OU and selecting Export List…

And saving the export as csv, this gives us the Display and UPN names.
The photo filenames we grab from our school supplier who provides the photos in cases code format. By dumping a directory listing piped to a csv we can then use the list to merge with the AD export list –

We build this script using reference from – https://m365scripts.com/microsoft365/manage-microsoft-365-user-photos-using-ms-graph-powershell/#Managing%20Microsoft%20365%20Group%20Profile%20Photos%20using%20PowerShell