Answer the question
In order to leave comments, you need to log in
How to add photo to user's jpegPhoto and thumbnailPhoto attributes in AD using PowerShell GUI?
I'm trying to make a simple form (using the PowerShell GUI) to edit user attributes.
The form has three controls, two Buttons ("Select Photo" and "Apply Changes") and a PictureBox.
The idea is this:
When I click the "Select Photo" button, I select an arbitrary image, for example userPhoto.jpg. Using the Resize-Image function, I reduce the image to the desired size and insert it into the PictureBox.
$imgFile = (get-item $openfiledialog.FileName)
$picturebox.Image = Resize-Image -InputFile $imgFile
Set-ADUser -Identity testUser -Replace @{ thumbnailPhoto = $picturebox.Image }
Set-ADUser -Identity testUser -Replace @{ jpegPhoto = $picturebox.Image }
Invalid type 'System.Management.Automation.PSCustomObject'.
Parameter name: thumbnailPhoto
+ CategoryInfo : InvalidArgument: (testUser:ADUser) [Set-ADUser], ArgumentException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
+ PSComputerName : DC1.local.example.net
Invalid type 'System.Management.Automation.PSCustomObject'.
Parameter name: jpegPhoto
+ CategoryInfo : InvalidArgument: (testUser:ADUser) [Set-ADUser], ArgumentException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.SetADUser
+ PSComputerName : DC1.local.example.net
Answer the question
In order to leave comments, you need to log in
Seems to have figured it out.
It turned out something like this:
$stream = New-Object System.IO.MemoryStream
$picturebox.Image.Save($stream, [System.Drawing.Imaging.ImageFormat]::Jpeg) | Out-Null
[byte[]]$pictureData = $stream.ToArray()
$stream.Dispose()
Set-ADUser -Identity testUser -Replace @{ thumbnailPhoto = $pictureData; jpegPhoto = $pictureData }
You need to convert the photo before uploading it to AD
$photo = [byte[]](Get-Content "C:\temp\crusoe.jpg" -Encoding byte)
Set-ADUser -Identity testUser -Replace @{thumbnailPhoto=$photo }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question