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 824 times – 893 B
Hi Jake, Can you share how to remove the photos that was using CodeTwo to upload. I used CodeTwo to upload a photo for a user. The user requested to change his photo. So I used CodeTwo to remove his old photo and upload a new one to him. But the user found his outlook still display his old photo. I saw your blog above and mentioned the CodeTwo is hash within ADSI edit. So just wanna to know how to remove the photo that using CodeTwo uploading.
Hi Eddy,
If the photo was added using CodeTwo you should be able to use CodeTwo to also remove that photo. If try
Get-ADUser -Identity "SamAccountName" | Set-ADUser -Clear thumbnailphoto
.Best, Jake