|
-
Jun 8th, 2005, 08:41 AM
#1
Thread Starter
Hyperactive Member
activedirectory get OUs from username
I need to get the ous that a user belongs to from the username
is this possible?
-
Jun 8th, 2005, 09:21 AM
#2
Thread Starter
Hyperactive Member
Re: activedirectory get OUs from username
early there. i have managed to drill through ad to find where a particular user is located. however for some reason the fChild.username property is alway nothing. why would this be? looking in active directory the username is there, so why isn't the property picking it up?
any help would be appreciated
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
Dim oOU As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Dim oChild As DirectoryServices.DirectoryEntry
Dim fChild As DirectoryServices.DirectoryEntry
For Each oChild In oOU.Children
'MsgBox(oChild.Path)
If oChild.Name = "OU=Centre" Then
Dim sChild As DirectoryServices.DirectoryEntry
For Each sChild In oChild.Children
If sChild.Name = "OU=General Users" Then
Dim tChild As DirectoryServices.DirectoryEntry
For Each tChild In sChild.Children
For Each fChild In tChild.Children
If fChild.Username = "myusername" Then
MsgBox(tChild.Name & " : " & fChild.Name)
End If
Next
Next
End If
Next
End If
Next
End Sub
-
Jun 8th, 2005, 09:42 AM
#3
Thread Starter
Hyperactive Member
Re: activedirectory get OUs from username[RESOLVED]
got it. don't know why the username property is nothing,
but found i could use the sAMAccountName property to get it (don't know why)
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
Dim oOU As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Dim oChild As DirectoryServices.DirectoryEntry
Dim fChild As DirectoryServices.DirectoryEntry
For Each oChild In oOU.Children
'MsgBox(oChild.Path)
If oChild.Name = "OU=Centre" Then
Dim sChild As DirectoryServices.DirectoryEntry
For Each sChild In oChild.Children
If sChild.Name = "OU=General Users" Then
Dim tChild As DirectoryServices.DirectoryEntry
For Each tChild In sChild.Children
For Each fChild In tChild.Children
If fChild.Properties("sAMAccountName").Value = "myname" Then
MsgBox(tChild.Name & " : " & fChild.Name)
End If
Next
Next
End If
Next
End If
Next
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|