I have been trying to set user's properties for AD accounts and have made it
pretty far. But now I have an error that I can't find an answer too. Here is
my code. The problem is that in my ModifyUserProperties Sub the Term
GetDirectoryEntry says Directory Entry cannot be indexed because it has no
default property. Does anyone have any idea as I am at a deadend.
Public Shared Function GetDirectoryEntry() As DirectoryEntry
Dim de As DirectoryEntry = New DirectoryEntry()
de.Path = "LDAP://ipaddress"
de.Username = "domain\username"
de.Password = "password"
return de
End Function
Public Sub ModifyUserProperties(ByVal displayname As String, ByVal
department As String, ByVal title As S)
Dim de As DirectoryEntry = GetDirectoryEntry()
Dim ds As DirectorySearcher = New DirectorySearcher(de)
ds.Filter =
"(&(objectCategory=Person)(objectClass=user)(displayName=" + displayname +
"))"
ds.SearchScope = SearchScope.Subtree
Dim results As SearchResult = ds.FindOne()
If Not results Is Nothing Then
Dim dey As DirectoryEntry = GetDirectoryEntry(results.Path)
problem is here
SetProperty(dey, "employee-id", EmplID.Text)
dey.CommitChanges()
dey.Close()
End If
de.Close()
End Sub
Public Shared Sub SetProperty(ByVal de As DirectoryEntry, ByVal PropertyName
As String, ByVal PropertyValue As String)
If Not PropertyValue Is Nothing Then
If de.Properties.Contains(PropertyName) Then
de.Properties(PropertyName)(0) = PropertyValue
Else
de.Properties(PropertyName).Add(PropertyValue)
End If
End If
End Sub
Archived from group: microsoft>public>vb>enterprise