VBS List all groups in domain
20 January, 2011 at 9:27 am Leave a comment
‘=====================================
‘list all groups in domain
‘to run: cscript name.vbs > outputName.txt
‘i copy from somewhere, it works beautifully
‘=====================================
On Error Resume Next
Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet, gt
Set objConnection = CreateObject(“ADODB.Connection”)
Set objCommand = CreateObject(“ADODB.Command”)
objConnection.Provider = “ADsDSOOBject”
objConnection.Open “Active Directory Provider”
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject(“LDAP://RootDSE”)
‘Get domain
strDNSDomain = objRootDSE.Get(“defaultNamingContext”)
strBase = “<LDAP://” & strDNSDomain & “>”
‘Define the filter elements
strFilter = “(&(objectCategory=group))”
‘List all attributes you will require
strAttributes = “displayName,sAMAccountName,groupType”
‘compose query
strQuery = strBase & “;” & strFilter & “;” & strAttributes & “;subtree”
objCommand.CommandText = strQuery
objCommand.Properties(“Page Size”) = 99999
objCommand.Properties(“Timeout”) = 300
objCommand.Properties(“Cache Results”) = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields(“displayName”)
strSA = objRecordSet.Fields(“sAMAccountName”)
gt = objRecordSet.Fields(“groupType”)
if (gt And &h01) <> 0 Then
Scope = “Built-in”
Elseif (gt And &h02) <> 0 Then
Scope = “Global”
Elseif (gt And &h04) <> 0 Then
Scope = “Domain Local”
Elseif(gt And &h08) <> 0 Then
Scope = “Universal”
End If
If (gt And &h80000000) <> 0 Then
SecDst = “Security”
Else
SecDst = “Distribution”
End If
Wscript.Echo Scope & vbTab & SecDst & vbTab & strDN & vbTab & strSA
objRecordSet.MoveNext
Loop
‘ Clean up.
objConnection.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
Entry filed under: IT/Soft.
Trackback this post | Subscribe to the comments via RSS Feed