Today, I looked at how to retrieve a list of users that don’t have a user profile photo using PowerShell.Once again I’m using PnP PowerShell. First I connect to my admin site of my tenant:[code lang=text]
Connect-PnPOnline https:\ \mytenant-admin.sharepoint.com
[/code]Then I collect the properties of my user profile:[code lang=text]
$user = Get-PnPUserProfileProperty -Account username@mytenant.onmicrosoft.com
[/code]$user.PictureUrl now contains the Url to my profile picture.Ok, this is the first step of the task. Now I need to go through all my users.[code lang=text]
Connect-SPOService -Url https:/ /mytenant-admin.sharepoint.com
Get-SPOUser -Site https:/ /mytenant.sharepoint.com
[/code]Ok, so now I’ve got all my user login details.[code lang=text]
$loginnames = Get-SPOUser -Site https:/ /mytenant.sharepoint.com | select -Property LoginName
[/code]Now some plumbing around the code so far and the list of users is returned:[code lang=text]
$cred = Get-Credential -Message “Password” -UserName admin@mytenant.onmicrosoft.comConnect-PnPOnline https:/ /mytenant-admin.sharepoint.com -Credentials $cred
Connect-SPOService -Url https:/ /mytenant-admin.sharepoint.com -Credential $cred
$loginNames = Get-SPOUser -Site https:/ /mytenant.sharepoint.com | select -Property LoginName
foreach($loginName in $loginNames)
{$user = Get-PnPUserProfileProperty -Account $loginName.LoginName
if ($user.PictureUrl -eq “” -or $user.PictureUrl -eq $null )
{
Write-Host $loginName
}
}
[/code]
Frequently asked questions
How does the example find missing profile photos?
It gets site user login names, retrieves each user profile and reports accounts whose PictureUrl is empty or null.
Does this necessarily enumerate every tenant user?
No. The example uses users returned for a specified SharePoint site, so its scope is not a guaranteed complete tenant inventory.
Are the authentication and commands current?
The script is historical; check current PnP PowerShell and SharePoint Online management documentation for supported authentication and cmdlets.
Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like.
I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide.
For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions.
SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/
Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/
You can contact me using contact@sharepains.com