Store Pictures in Active Directory

by Nov 28, 2011

When you need to store a picture into an AD account, the picture will have to be converted to byte values before it can be stored. Just make sure you adjust the path to the picture you want to store and the LDAP path of the AD object you want the picture to be stored in:

# adjust picture path:
$file = "C:\pic.jpg"

$bild = New-Object system.Drawing.Bitmap($file)

$ms = New-Object IO.MemoryStream
$bild.Save($MS, 'jpeg')
$byte = $MS.ToArray()

# adjust user LDAP path:
$user = New-Object System.DirectoryServices.DirectoryEntry`
$User.Properties["jpegPhoto"].Value = $byte

Twitter This Tip!
ReTweet this Tip!