Add Photo to ADUser from csv with Base64Data


I’m looking for a way to take a CSV full of Base64Image data and add it to the AD User profiles.

I’m not sure of the size of each file either so I will need to resize to something AD will accept in the script.

Any help would be appreciated.


Thanks for your time and patience.

You don’t say what you have tried or search for. We are here to help, but asking folks to do your work for you is why consultants exist. 8^}

So, you have a CSV Base64Image data strings, not real pictures, meaning created using other tool?

ADDS will only take pictures of a given size, and this is documented in the MS TechNet/MSDN documentation and many blogs all over the web.

So, you need to know the file size of each image (recommended thumbnail photo size is 96x96 pixels and maximum size of photo that can be imported with the Import-RecipientDataProperty command is 10-KB), and if it does not meet the ADDS specifications, you need to fix that.

There are many examples and even pre-built script showing how to import images in to ADDS, for example:

There are many similar locations taking to converting image to base64, and we can only image some of there tools were used or done say this way…

# Convert image to base64
$b64 = [convert]::ToBase64String((Get-Content 'F:\Pictures\SecureZip.jpg' -encoding byte))

All that being said, converting and resizing on the fly, that is a different process
Converting, base64 string back to a file, say, using something like...

The FromBase64String() method converts a base64-encoded string to a byte array. All you need to do is write that byte array back to a file:

# Path to new image file
$filename = 'D:\temp\imagefile.jpg'

# Convert base64 image back to image file
$bytes = [Convert]::FromBase64String("$b64")
[IO.File]::WriteAllBytes($filename, $bytes)

Then resizing that image using say this:

Ok, apologies for just shooting it out there. Not used to asking on the forum.

I am stuck trying to get a CSV dump of EmployeeID numbers along with the Base64String of their pictures from our HRIS system and then importing them into AD.

So I have 2 separate pieces I’m guessing.

One looks something like


Import-Csv-Path".\ActiveDirectory_WorkerPhotos_1.csv"|foreach {




Set-ADUser-Replace @{thumbnailPhoto=(byte[])} $_.username-FilePath$filename


I know, it’s a mess but I’m at the ragged edge of my PS knowledge as of now so…








As for this…

... I am stuck trying to get a CSV dump of EmployeeID numbers along with the Base64String of their pictures from our HRIS system ...
I cannot help you with this one=, since I have no idea what it is. You must get:
  1. this into a CSV
  2. Write each picture to a real file
  3. resize those files
  4. then import to ADDS
# Export data from HRIS as a file. this file contains username
# and the Base64String of their picture. 
#  Username,UserPicture


Import-Csv-Path".\hrisuserpictures.csv" |
foreach {
$filename = ".$($.Username).jpg"
$bytes = [Convert]::FromBase64String($($

Resize-Image -InputFile $filename -Width 96 -Height 96 -Display
Set-ADUser-Replace @{thumbnailPhoto = ([byte[]](Get-Content -Path $filename -Encodingbyte))} $_.username -FilePath$filename


Of course I have no way of testing this, as my environment does not use pictures.
Well, that and that spending time trying to recreate what your HRIS system would provide,
is not really reproduceable thing.