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. Tags: .

shadow [VB] List all active users in OU whose displayName is different to CN (pre: have OU and domain name)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


January 2011
M T W T F S S
« Dec   Feb »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Categories


%d bloggers like this: