Today, I looked at how to retrieve a list of users that don’t have a user profile picture using PowerShell.

Once again I’m using PnP PowerShell. First I connect to my admin site of my tenant:

Connect-PnPOnline https:\ \mytenant-admin.sharepoint.com

Then I collect the properties of my user profile:

$user = Get-PnPUserProfileProperty -Account username@mytenant.onmicrosoft.com

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

 

Connect-SPOService -Url https:/ /mytenant-admin.sharepoint.com
Get-SPOUser -Site https:/ /mytenant.sharepoint.com

users

Ok, so now I’ve got all my user login details.

$loginnames = Get-SPOUser -Site https:/ /mytenant.sharepoint.com | select -Property LoginName

 

Now some plumbing around the code so far and the list of users is returned:

$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
  }
}

 

 

 

Advertisements