Unable to Update LDAP property "department"
-
I'm trying to create a utility to perform a mass update of our Active Directory and all I get is the error, "Server is unwilling to process request." Below is my code:
Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
Dim ds As New DirectorySearcher(de) ds.PropertiesToLoad.Add("department") ds.SearchScope = SearchScope.Subtree Dim ue As New DirectoryEntry ds.Filter = String.Format("(SAMAccountName={0})", Me.tboxUserName.Text) Try ue = ds.FindOne.GetDirectoryEntry For Each sproperty As String In ue.Properties.PropertyNames debug.print(String.Format("{0}{1} : {2} ", System.Environment.NewLine, sproperty, ue.Properties(sproperty)(0))) Next ' test the update here ... If (ue.Properties.Contains("department")) Then ue.Properties("department").Value = "IT" Else ue.Properties("department").Add("IT") End If ue.CommitChanges() ue.RefreshCache() ue.Close() Catch ex As Exception debug.print (ex.Message) End Try
The code seems to connect to the LDAP server and retrieve the correct user because I can see valid data being displayed from the ue.Properties.PropertyNames collection. The error is thrown on the "CommitChanges()" line. BTW: This demo program is a WinForms .NET 4.0 applicaiton I have tried it passing no credentials and passing valid domain credentials and I get the same " ... unwilling to process request." error. What am I doing wrong?
-
I'm trying to create a utility to perform a mass update of our Active Directory and all I get is the error, "Server is unwilling to process request." Below is my code:
Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
Dim ds As New DirectorySearcher(de) ds.PropertiesToLoad.Add("department") ds.SearchScope = SearchScope.Subtree Dim ue As New DirectoryEntry ds.Filter = String.Format("(SAMAccountName={0})", Me.tboxUserName.Text) Try ue = ds.FindOne.GetDirectoryEntry For Each sproperty As String In ue.Properties.PropertyNames debug.print(String.Format("{0}{1} : {2} ", System.Environment.NewLine, sproperty, ue.Properties(sproperty)(0))) Next ' test the update here ... If (ue.Properties.Contains("department")) Then ue.Properties("department").Value = "IT" Else ue.Properties("department").Add("IT") End If ue.CommitChanges() ue.RefreshCache() ue.Close() Catch ex As Exception debug.print (ex.Message) End Try
The code seems to connect to the LDAP server and retrieve the correct user because I can see valid data being displayed from the ue.Properties.PropertyNames collection. The error is thrown on the "CommitChanges()" line. BTW: This demo program is a WinForms .NET 4.0 applicaiton I have tried it passing no credentials and passing valid domain credentials and I get the same " ... unwilling to process request." error. What am I doing wrong?
According to http://forums.asp.net/t/1809557.aspx/1[^], the problem arises by using the wrong protocol:
Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
replace that withDim de As New DirectoryEntry(**@"LDAP:\\**DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
-
According to http://forums.asp.net/t/1809557.aspx/1[^], the problem arises by using the wrong protocol:
Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
replace that withDim de As New DirectoryEntry(**@"LDAP:\\**DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
Thank you so much. My program is now working. :thumbsup: I've been trying so many combinations that I must have overlooked the obvious.