How to Determine Which SharePoint Users Have a Profile Picture

I recently needed a means of getting a list of all users who had a profile picture associated with their SharePoint account (well, the client was actually more interested in knowing who didn’t have a profile picture, but this result below worked for them). Below is a simple PowerShell script for being able to get a list of the user names, and the URL of their profile picture (if they had one). In the case of users who did not have a profile picture, their “PictureURL” value was empty, and these were ultimately the values the client was after (to encourage all users to upload a profile picture).

[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server”)
[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server.UserProfiles”)
[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

# Change your URL below
$spsite = new-object Microsoft.SharePoint.SPSite(“https://[sharepoint.company.com]“);
$spsc = [Microsoft.SharePoint.SPServiceContext]::GetContext($spsite);
$sppm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($spsc)
$profiles = $sppm.GetEnumerator()

write-host “Display Name ; Account Pic”

foreach ($profile in $profiles)
{
    $DisplayName = $profile.DisplayName    
    $AccountPic = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::PictureURL].Value

    if ($AccountPic -ne “” -AND $AccountPic -ne ” ” -AND $AccountPic -ne $NULL)
    {
        write-host $DisplayName, “; [“, $AccountPic, “];”
    }
}

$spsite.Dispose()

Enjoy!