Find and Export Office 365 Users Profile Picture Status using PowerShell

In this post, I am going to share powershell script to find a list of users without profile picture in Office 365. We can extract this report using Exchange Online powershell cmdlets Get-Mailbox and Get-Userphoto.

Before proceed run the following command to connect Exchange Online powershell module.

$365Logon = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $365Logon -Authentication Basic -AllowRedirection
Import-PSSession $Session

Check if specific user has profile picture or not :

The following command checks whether profile photo set or not set for the user “[email protected]”.

$photoObj = Get-Userphoto -Identity "[email protected]" -ErrorAction SilentlyContinue
If($photoObj.PictureData -ne $null)
{
Write-Host "User has profile picture"
}
Else
{
Write-Host "Profile picture not configured"
}

Export Office 365 Users without profile picture to CSV file :

Run the following powershell script to get a list of users who do not have profile picture and export user details to csv file.

$Result=@()
$allUsers = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited
$totalusers = $allUsers.Count
$i = 1 
$allUsers | ForEach-Object {
$user = $_
Write-Progress -activity "Processing $user" -status "$i out of $totalusers completed"
$photoObj = Get-Userphoto -identity $user.UserPrincipalName -ErrorAction SilentlyContinue
If($photoObj.PictureData -eq $null) 
{
$Result += New-Object PSObject -property @{ 
UserName = $user.DisplayName
UserPrincipalName = $user.UserPrincipalName
}}
$i++
}
$Result | Export-CSV "C:\office-365-users-without-photo.csv" -NoTypeInformation -Encoding UTF8

Export all O365 Users with profile picture status :

The following powershell script exports all mailbox users with their profile picture status (photo uploaded or not) to csv file.

$Result=@()
$allUsers = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited
$totalusers = $allUsers.Count
$i = 1 
$allUsers | ForEach-Object {
$user = $_
Write-Progress -activity "Processing $user" -status "$i out of $totalusers completed"
$photoObj = Get-Userphoto -identity $user.UserPrincipalName -ErrorAction SilentlyContinue
$hasPhoto = $false
if ($photoObj.PictureData -ne $null)
{
$hasPhoto = $true
}
$Result += New-Object PSObject -property @{ 
UserName = $user.DisplayName
UserPrincipalName = $user.UserPrincipalName
HasProfilePicture = $hasPhoto 
}
$i++
}
$Result | Export-CSV "C:\office-365-users-photo-status.csv" -NoTypeInformation -Encoding UTF8


CSV Output of Profile Picture Status Report:

Find and Export O365 Profile Photo Status Report to CSV file


Advertisement

5 thoughts on “Find and Export Office 365 Users Profile Picture Status using PowerShell”

    • Can you please ensure the user has profile picture in owa (Outlook Web Access) portal?

      Synchronizing profile picture in all work loads(SPO, Mailbox, OneDrive, etc..) takes some time

      Reply

Leave a Comment