I am trying to set the value of an extension attribute in AD with my VB.NET executable. I extended the UserPrincipal
class to accomplish this but now I get an error
The server is unwilling to process the request
when I try to set the extended property.
I can get that property from an existing user in AD without any errors and when I try to create and save the user without the extended class it works.
Dim stringDomainName As String = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName
Dim objPrincipalContext As New PrincipalContext(ContextType.Domain, stringDomainName, DirectoryPath, ContextOptions.SimpleBind, DomainUsername, DomainPassword)
Dim objUserPrincipal As New UPExtention(objPrincipalContext, sUserName, sPassword, True)
Dim expDate As Date
'Set Name
objUserPrincipal.Name = sFirstName & " " & sLastName
'Set First Name
objUserPrincipal.GivenName = sFirstName
'Set Last Name
objUserPrincipal.Surname = sLastName
'Set Display Name
objUserPrincipal.DisplayName = sLastName & ", " & sFirstName
'Enable Account
objUserPrincipal.Enabled = True
objUserPrincipal.extentionAttribute15 = sUserName
'Save the created user
objUserPrincipal.Save(objPrincipalContext)
I'm not 100% sure what was causing the error but I went back to using the unextended UserPrincipal class to create the initial object and saved it without setting the extension attribute. Then I created an object of the extended UserPrincipal and used the overloaded FindByIdentity function to get the user I just created and then set the extension attribute and saved again. Now it works!