Exporting a list of users with no profile picture in a specific OU via Azure AD Powershell

Blank_Ini 1 Reputation point
2022-09-30T08:51:16.413+00:00

So I haven't used PowerShell in a while wondering the best way to Export specific OU's users that do not have profile pictures tied to their account via Powershell.

https://learn.microsoft.com/en-us/answers/questions/31510/how-can-i-get-the-list-of-users-with-profile-pictu.html followed something similar to this but nothing returns the information I need.

Not urgent but any help would be appreciated.

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,751 Reputation points
    2022-09-30T15:36:04.643+00:00

    Hello there,

    Following are the requirements before we get started. Make sure you set up your environment with these:

    -Azure AD Administrator
    -Exchange Online Administrator
    -AzureAD PowerShell Module
    -Exchange Online PowerShell Module (only if MFA is in use)

    First and foremost, we need to fetch the Office365 credentials and then connect to Azure Active Directory and Exchange Online.

    $cred = get-Credential
    Connect-AzureAD -Credential $cred
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
    Import-PSSession $Session
    $Users = Get-AzureADUser | Where {$.UserType -eq 'Member' -and $.AssignedLicenses -ne $null}
    $NoPicUsers = @()
    foreach ($user in $Users)
    {
    $Picture = Get-UserPhoto -Identity $user.UserPrincipalName -ErrorAction SilentlyContinue
    if ($Picture -eq $null)
    {
    $NoPicUsers += $user
    }
    }

    ------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.