Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Find all groups that are managed by a user

Hi,

I want to Find all groups that are managed by a user.

Regards
Sharath
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of William Elliott
name <tab> owner

Option Explicit

Dim adoConnection, adoCommand, objRootDSE, strDNSDomain, strQuery
Dim adoRecordset, strDN, objGroup, results

' Use ADO to search Active Directory.
Set adoConnection = CreateObject("ADODB.Connection")
Set adoCommand = CreateObject("ADODB.Command")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Determine the DNS domain from the RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Search for all groups, return the Distinguished Name of each.
strQuery = "<LDAP://" & strDNSDomain _
    & ">;(objectClass=group);distinguishedName;subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

Set adoRecordset = adoCommand.Execute
If (adoRecordset.EOF = True) Then
    results = results & "No groups found" & vbcrlf
    adoRecordset.Close
    adoConnection.Close
    Set objRootDSE = Nothing
    Set adoConnection = Nothing
    Set adoCommand = Nothing
    Set adoRecordset = Nothing
    Wscript.Quit
End If

' Enumerate all groups, bind to each, and document group members.
Do Until adoRecordset.EOF
    strDN = adoRecordset.Fields("distinguishedName").Value
    ' Escape any forward slash characters with backslash.
    strDN = Replace(strDN, "/", "\/")
    Set objGroup = GetObject("LDAP://" & strDN)
    results = results & objGroup.sAMAccountName _
        & vbtab & objGroup.owner & vbcrlf
    adoRecordset.MoveNext
Loop
wscript.echo results
adoRecordset.Close

' Clean up.
adoConnection.Close
Set objRootDSE = Nothing
Set objGroup = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
Set adoRecordset = Nothing
Avatar of bsharath

ASKER

weellio
No results come out...

this works,..


on error resume next
Dim adoConnection, adoCommand, objRootDSE, strDNSDomain, strQuery
Dim adoRecordset, strDN, objGroup, results

' Use ADO to search Active Directory.
Set adoConnection = CreateObject("ADODB.Connection")
Set adoCommand = CreateObject("ADODB.Command")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Determine the DNS domain from the RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Search for all groups, return the Distinguished Name of each.
strQuery = "<LDAP://" & strDNSDomain _
    & ">;(objectClass=group);distinguishedName;subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False



Set adoRecordset = adoCommand.Execute
If (adoRecordset.EOF = True) Then
    results = results & "No groups found" & vbcrlf
    adoRecordset.Close
    adoConnection.Close
    Set objRootDSE = Nothing
    Set adoConnection = Nothing
    Set adoCommand = Nothing
    Set adoRecordset = Nothing
    Wscript.Quit
End If

' Enumerate all groups, bind to each, and document group members.
Do Until adoRecordset.EOF
    strDN = adoRecordset.Fields("distinguishedName").Value
    ' Escape any forward slash characters with backslash.
    strDN = Replace(strDN, "/", "\/")
    Set objGroup = GetObject("LDAP://" & strDN)
      strManagedBy = "No_owner"
      strManagedBy = objGroup.Get("managedBy")
    results = results & objGroup.sAMAccountName _
        & vbtab & strManagedBy & vbcrlf
    adoRecordset.MoveNext
Loop
wscript.echo results
adoRecordset.Close

' Clean up.
adoConnection.Close
Set objRootDSE = Nothing
Set objGroup = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
Set adoRecordset = Nothing
I tried this but there is no error nor output....