r3nder
asked on
Getting the target OU in Active Directory
I am trying to get the groups out of Active Directory - I can get them all, thats no problem
What I am trying to do is get a list of groups out of a target directory
For example LDAP://COMPANY.COM/AN-OU/T ARGET-OU
The code I am using is this
What I am trying to do is get a list of groups out of a target directory
For example LDAP://COMPANY.COM/AN-OU/T
The code I am using is this
Public Shared Function GetAllGroups() As DataSet
Dim dsGroup As New DataSet()
Dim dirEntry As DirectoryEntry = New DirectoryEntry("LDAP://COMPANY.com", "USERNAME", "PASS")
'create instance fo the direcory searcher
Dim dirSearch As New DirectorySearcher()
'set the search filter
dirSearch.SearchRoot = dirEntry
'deSearch.PropertiesToLoad.Add("cn");
'dirSearch.Filter = ("(OU=AN-OU,OU=TAGET_OU)")
dirSearch.Filter = "(objectClass=group)" '(&(objectClass=group)(cn=CS_*)) check on this!!!
'dirSearch.Filter = "(&(OU=AN_OU,OU=TARGET-OU,DC=COMPANY,DC=com)"
'dirSearch.SearchScope = SearchScope.Subtree
'find the first instance
Dim searchResults As SearchResultCollection = dirSearch.FindAll()
'Create a new table object within the dataset
Dim dtGroup As DataTable = dsGroup.Tables.Add("Groups")
dtGroup.Columns.Add("GroupName")
'if there are results (there should be some!!), then convert the results
'into a dataset to be returned.
If searchResults.Count > 0 Then
'iterate through collection and populate the table with
'the Group Name
For Each Result As SearchResult In searchResults
'set a new empty row
Dim drGroup As DataRow = dtGroup.NewRow()
'populate the column
drGroup("GroupName") = Result.Properties("cn")(0)
'append the row to the table of the dataset
dtGroup.Rows.Add(drGroup)
Next
End If
Return dsGroup
End Function
ASKER
I have a hierarchy pic of the OU, but are you saying
Dim dirEntry As DirectoryEntry = New DirectoryEntry("LDAP://OU= Target,DC= Company,DC =COM", "USERNAME", "PASS")
or what
Capture.JPG
Dim dirEntry As DirectoryEntry = New DirectoryEntry("LDAP://OU=
or what
Capture.JPG
Your ldap syntax should LDAP:// OU=Target OU ,OU=AN OU,DC=company,DC=com
You work backwards. The lowest in the hierarchy to the highest. Where .com is your last in the list.
Have you tried dsquery ?
You work backwards. The lowest in the hierarchy to the highest. Where .com is your last in the list.
Have you tried dsquery ?
ASKER
not yet I am trying to figure out with my function how I would use that
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also why not use the querys saved feature in ADUC.
You can accomplish this and see the query that is being built to meet your needs.
You can accomplish this and see the query that is being built to meet your needs.
ASKER
I will have a chance to test it tomorrow - I will let you know - thanks for all your help yo_bee
No problem
ASKER
Cool - that is a neet tool - I will use it first thing in the morning - thanks for your wealth of knowledge
With this free tool , you can select the Groups option , then select All groups , then select the OU and choose the Attributes that you need in the report .
http://www.cjwdev.co.uk/Software/ADReportingTool/Info.html
http://www.cjwdev.co.uk/Software/ADReportingTool/Info.html
ASKER
Excellect person, knowledgable and the solution was perfect
@r3nder
Did you even try to apply the VB code snippet, DSQUERY or even my suggestion for ADUC?
Did you even try to apply the VB code snippet, DSQUERY or even my suggestion for ADUC?
ASKER
I apologize yo_bee I had intended that the credit go to you, I have notified the moderators and have asked them to give YOU the points
Once again I appologize
R3nder
@MilesLogan
Sorry man my fault yo_bee did all the work
Once again I appologize
R3nder
@MilesLogan
Sorry man my fault yo_bee did all the work
It's ok, I was just curious if any of the solutions I suggested worked?
If so which one
If so which one
ASKER
I changed the LDAP to what you suggested and changed the filter to what you suggested in the previous code snippet - worked like a charm - I will do my utmost to ensure you get the points - also that part about expert and knowledgable was to you
Thanks Yo_Bee
Thanks Yo_Bee
Thank you, but if not I have enough. Just glad you confirmed what worked.
all good with me , I get so much help from people here not really an issue with me about points ..
I will try his option also when I have time .
I will try his option also when I have time .
I am going to look into the link recommend.
ASKER
Thank you yo_bee
Where did you get the original script from?
ASKER
I found it on the web - There is another question of mine you might want to chime in on (getting the group GUID at the same time)
LDAP syntax should be LDAP://dc=company,dc=com and if you are looking for an OU your would do it like this LDAP://OU=Target,DC=Compan
If you are just looking for a group you can use DSQUERY.
You can also use DSQUERY Group or DSGET Group to output the Distinguished names.