Using a script to determine who doesn't have profile photos.

Joe Grover 566 Reputation points
2022-02-25T15:03:51.867+00:00

We are currently in a hybrid Exchange/365 environment. We need to find out who doesn't have photos attached to their accounts. Unfortunately the scripts I'm using are indicating people don't have photos that do in fact have them, so I'm not getting anywhere.

First I tried this script against my local AD:

get-aduser -searchbase 'OU=Users,DC=mydomain,DC=local' -Filter {(Enabled -eq $true)} | Where {$_.thumbnailPhoto -eq $NULL} 

This output every user in the OU. Picking a user I knew had a photo (like myself) I exported all of the attributes of the user and there was no thumbnailPhoto attribute. There was however a jpegPhoto attribute, but changing the query to look for jpegPhoto -eq $NULL returned no results at all.

So then I found a script to run against Exchange Online. I connected to it via Powershell and ran the following:

get-mailbox -resultsize Unlimited -RecipientTypeDetails Usermailbox | Where {$_.HasPicture -eq $false} | Select-Object DisplayName,UserPrincipalName,HasPicture

Again, this output everybody, including myself (who definitely has a picture).

What am I missing here?

Exchange Exchange Server Management
{count} votes

Accepted answer
  1. Gary Reynolds 9,621 Reputation points
    2022-02-25T19:07:06.407+00:00

    Hi Joe,

    The LDAP query to return all users with neither the thumbnailphoto or jpegphoto set is:

    (&(Objectclass=user)(!thumbnailphoto=*)(!jpegphoto=*))
    

    You can use this with the -ldapfilter parameter with the get-user powershell command to get all the user without a picture in AD.

    Gary.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.