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