Hello everyone. Today a colleague asked me if I know of a simple way to get user pictures from Active Directory. Of course I do and I will show you how you can get and set pictures in Active Directory by using PowerShell.
Important: The following scripts require Remote Server Administration Tools to be installed on your computer if you do not run them on a Domain Controller.
To get pictures from a user in Active Directory simply run the script below and provide a UserName and a Path (For example: C:\example.jpg) where the picture should be stored:
Param([parameter(Mandatory=$true)][alias("User")]$UserName, [parameter(Mandatory=$true)][alias("Picture")]$PicturePath) Import-Module ActiveDirectory $user = Get-ADUser $UserName -Properties thumbnailPhoto $user.thumbnailPhoto | Set-Content $PicturePath -Encoding byte
To update a users photo simply run the script below and provide a UserName and Path of the new picture:
Param([parameter(Mandatory=$true)][alias("User")]$UserName, [parameter(Mandatory=$true)][alias("Picture")]$PicturePath) Import-Module ActiveDirectory $photo = [byte[]](Get-Content $PicturePath -Encoding byte) Set-ADUser $UserName -Replace @{thumbnailPhoto=$photo}
That´s it. You can get/set pictures in Active Directory as simple as this.
As always you can download my scripts from here.
Sources: