I am writing a script that contains this code:
Get-ADUser -Identity johndoe | Set-ADUser -Replace @{customattribute = 'yes'}
...and I am getting this error:
Set-ADUser : An attempt was made to modify an object to include an
attribute that is not legal for its class
At line:1 char:61
+ Get-ADUser -Identity johndoe | Set-ADUser -Replace...
+
~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=John
Doe,DC=test,DC=local:ADUser) [Set-ADUser], ADException
+ FullyQualifiedErrorId :
ActiveDirectoryServer:8317,
Microsoft.ActiveDirectory.Management.Commands.SetADUser
If I do a Get-ADuser instead, I am able to see the custom attribute and the value assigned to it. It is just when I try modifying it with set-ADuser that I get the error.
Get-ADUser johndoe -Properties customattribute | ft name,customattribute
name customattribute
---- ---------------
John Doe No
I've done research and a lot of troubleshooting, but have not been able to solve the problem. Does anyone have any advice?
Thank you!