Getting Active Directory users thumbnail picture to disk with powershell

I am writing some examples now to PLVMUG presentation. Long story short, i wanted to get the AD thumbnail picture saved to disk. Spent 20-30 minutes on google , but only thing i was getting was how to upload the picture to Active Directory 😉 Well, after 20 mintues i decided to focus on writing it in that case.

$ADUser = (([adsisearcher]"Samaccountname=SomeUser").findone()).Properties
[byte[]]$imgdata = $ADUser.thumbnailphoto | %{ $_ }
$img = [System.Text.Encoding]::Default.GetString($imgdata)
Set-Content -path c:\myimage.jpeg -Value $img

So if we have uploaded before a picture to a user we should be able to save it now to C:\myimage.jpeg. Now the other thing that i was trying to achieve is to put that image to a picturebox object. So just for reference i will put it here as well. This way of injecting image to picturebox is not using files, instead it can read the image directly from variable like $img, from previous example. Found a solution here.

$ADUser = (([adsisearcher]"Samaccountname=SomeUser").findone()).Properties
[byte[]]$imgdata = $ADUser.thumbnailphoto | %{ $_ }
$picturebox1.Image= $image


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s