PowerShell error

I am running the following in PS:

Import-module ActiveDirectory
$Photo = [byte[]] (Get-content c:\Photos\jones.jpg -Encoding byte)
Set-User -identity Jones -Replace @[thumbnailPhoto=$photo}

This was working. Now I get the error "Set-AdUser: A value for the attribute was not in the acceptable range of values at: Line 3 char:10"    

I check the 'attributeID' in ADSIEdit, upperlimit value. It was set to <not set>. I set it to 64. I still get this error. Any thought?
Anthony K O365Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JonathanSpitfireSenior Solutions EngineerCommented:
line 3, character 10 is the - in front of "Identity".

Try running without the -identity switch, but further, here is some syntax that might achieve what you are trying to do:

Active Directory: Add or Update a User Picture using PowerShell

Hope this helps,

Anthony K O365Author Commented:
I ran it first w/o the identity switch and got same error. The Link you refenced shows the same script i used. I believe this has to do with an AD property setting.
Justin YeungSenior Systems EngineerCommented:
before you set-ADuser

why don't you confirm
get-aduser -identity Jones  

note: identify can be set as
distinguished name (DN), GUID, security identifier (SID), Security Accounts Manager (SAM) account name or name

confirm return successful before process the next step

if it does then do
Get-Aduser -identity Jones | Set-ADuser -Replace @[thumbnailPhoto=$photo}
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Anthony K O365Author Commented:
Same error.  It errors out right after 'Set-ADuser'  Again, it say "Attribute not in acceptable range of values." There is something about the Set-ADUser command. Not sure what it is.
Anthony K O365Author Commented:
Further investigation shows the script was complaining about the size of the .jpg photo. Apparently the AD value for thumbnail can not exceed 100k. My .jpg was 556k. Using a 65k .bmp file works fine!!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dhaval PandyaExchange AdministratorCommented:

User Below Script with CSV file to upload pic in AD with dimension of 96x96.

=========ps1 file script content==============

Add-Type -AssemblyName System.Drawing

$importfile = "c:\to\ps1\photo\picture.csv"

$importedusers = Import-CSV $importfile

foreach ($importeduser in $importedusers)


write-host "Uploading Photo for user.." -f "Green"

$Photofile = Get-ChildItem -Path $importeduser.file

      $Photo = [byte[]](Get-Content $Photofile.Fullname -Encoding byte)
      Set-ADUser -Identity $importeduser.SAM -Replace @{thumbnailPhoto=$Photo}


===========ps1 file end===================

Add users samaccount name and jpg file against each user to upload picture.

============picture.csv File Content==============


============CSV end=======================
Anthony K O365Author Commented:
This link was instrumental. http://outputequalsbaggs.blogspot.com/
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.