Active Directory – Remove Thumbnail Photo

A client recently had photos assigned to their user mailboxes, but they had been added in different ways. Some had been added using a piece of software called CodeTwo Active Directory Photos and some had been added using the command below

Set-UserPhoto “Joe Bloggs” -PictureData ([System.IO.File]::ReadAllBytes(“C:\Photos\JBloggs.jpg”)) –Confirm:$False

The ones that had been added using CodeTwo placed a hash within ADSI Edit under the users thumbnail attribute, of course making it harder to remove!

To make my life a little easier as I didn’t fancy removing 200+ users thumbnail hash manually, I created a script which imports a CSV with the users SamAccountName and clears the attribute.

The raw code is this:

# Import AD Module
Import-Module ActiveDirectory
write-Host 'Starting to update AD Attributes.......' -NoNewline -ForegroundColor Yellow
$users = Import-Csv -Path C:\Scripts\your-csv-file-here.csv
# Import CSV into variable $users
$users | foreach {
Get-ADUser -Identity $_.SamAccountName | Set-ADUser -Clear thumbnailphoto
}
Write-Host 'Complete!' -ForegroundColor Green

It does the job nicely and made things I lot quicker!! Feel free to edit the script to suit your needs.

Download “AD-RemovePhotos.ps1” AD-RemovePhotos.ps1 – Downloaded 149 times – 893 B

Be the first to comment on "Active Directory – Remove Thumbnail Photo"

Leave a comment

Your email address will not be published.


*