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]

users

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.com

Connect-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]

By Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: