Tuesday, 15 May 2018

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 "alexw@contoso.com".
$photoObj = Get-Userphoto -Identity "alexw@contoso.com" -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


Advertisements
Advertisements

5 comments:

  1. This is exactly what I needed. Thank you so much! It worked like a charm.

    ReplyDelete
  2. Hello Morgan,

    Could you please let me know how you get the distribution group members without a profile picture? I am replacing the following variable with the value provided below, but the script goes into a halt. I just need to see the output for a members of a specific distribution group. Thank you.

    $allUsers = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited

    with

    $allUsers = Get-DistributionGroupMember GroupName -ResultSize Unlimited

    ReplyDelete
    Replies
    1. Hi, you can also replace below line:

      $photoObj = Get-Userphoto -identity $user.UserPrincipalName -ErrorAction SilentlyContinue

      with

      $photoObj = Get-Userphoto -identity $user.ExternalDirectoryObjectId -ErrorAction SilentlyContinue


      The property "UserPrincipalName" will not be available in group member object so you need to use some other attribute like "ExternalDirectoryObjectId" to find user object in Azure AD.

      Delete
  3. Hi Morgan. Thanks for sharing the script. Is there a good solution to delay with the micro delay Microsoft apply every so often?
    Thanks

    ReplyDelete
    Replies
    1. Do you mean the delay in applying profile picture in different services, like SharePoint,OWA,Delve? Can you explain your need little bit clear?

      Delete