This PowerShell script sets the thumbnail photo of an Active Directory user with the username “MyUsername”. The script uses the Set-ADUser cmdlet to update the user object’s “thumbnailPhoto” attribute with the contents of a photo file located at “\\MySharedPath\Photo.jpg”.
The “-Replace” parameter specifies that the existing value of the “thumbnailPhoto” attribute should be replaced with the new photo. The “@{}” syntax creates a hash table where “thumbnailPhoto” is the key and the value is the byte array representation of the photo file contents, which is obtained by using the “Get-Content” cmdlet with the “-Encoding byte” parameter.
Set-ADUser MyUsername -Replace @{thumbnailPhoto=([byte[]](Get-Content "\\MySharedPath\Photo.jpg" -Encoding byte))}