0
votes

Im trying to update active directory users info and I added a new custom attribute to users, the new attribute calls certificate, and I was able to modify all attribute via powershell Set-Aduser excpet my new attribute. here is my powershell code and error: Code:

$user = Get-ADUser -Filter "SamAccountName -eq '$($Object.UserName)'" -Server $server -Credential $credential
     Set-ADUser -Identity $user -HomePage $Object.HomePage `
                                  -Description $Object.Description`
                                  -Title $Object.Title`
                                  -Officephone $Object.PhoneNumber`
                                  -Mobilephone $Object.Mobile`
                                  -Postalcode $Object.PostalCode`
                                  -City $Object.City`
                                  -State $Object.State`
                                  -Streetaddress $Object.StreetAddress`
                                  -Department $Object.Department`
                                  -Company $Object.Company
                                  -Certificat $Object.Certificat

Error:

Set-ADUser: Unable to bind the "Certificates" parameter. Unable to convert the value "Study Study" from type "System.String" to type
"System.Collections.Hashtable".
Au caractère C:\Users\test\Desktop\PP\AdInfoUpdater.ps1:40 : 43
+                               -Certificat $Object.Certificat
+                                           ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument : (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.SetADUser
1

1 Answers

2
votes

If it's a custom attribute, you will need to use the -Replace parameter or perhaps the -Add parameter e.g.

Set-AdUser userid -Replace @{'certificat'='CertificateStringValue'}

When PowerShell sees -Certificates (or even a shortened version of it like -Certif) it will parse that as referring to the userCertificate attribute in AD