wrkstat
asked on
Need script to generate a list of all of the groups in AD with the word Intranet in it
I am having a lot of trouble creating a script that works that lists all of the groups in our domain with the word Intranet in it.
Anyone have a sample script or can create a script that will do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also try this Vbscript
On Error Resume Next
Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet, gt
Set objConnection = CreateObject("ADODB.Connec tion")
Set objCommand = CreateObject("ADODB.Comman d")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio n = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE" )
'Get domain
strDNSDomain = objRootDSE.Get("defaultNam ingContext ")
strBase = "<LDAP://" & strDNSDomain & ">"
'Define the filter elements
strFilter = "(&(objectCategory=group)( name=*intr anet*)"
'List all attributes you will require
strAttributes = "distinguishedName,sAMAcco untName"
'compose query
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Pag e Size") = 99999
objCommand.Properties("Tim eout") = 300
objCommand.Properties("Cac he Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("disti nguishedNa me")
strSA = objRecordSet.Fields("sAMAc countName" )
Wscript.Echo strSA
objRecordSet.MoveNext
Loop
' Clean up.
objConnection.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
On Error Resume Next
Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet, gt
Set objConnection = CreateObject("ADODB.Connec
Set objCommand = CreateObject("ADODB.Comman
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio
Set objRootDSE = GetObject("LDAP://RootDSE"
'Get domain
strDNSDomain = objRootDSE.Get("defaultNam
strBase = "<LDAP://" & strDNSDomain & ">"
'Define the filter elements
strFilter = "(&(objectCategory=group)(
'List all attributes you will require
strAttributes = "distinguishedName,sAMAcco
'compose query
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Pag
objCommand.Properties("Tim
objCommand.Properties("Cac
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("disti
strSA = objRecordSet.Fields("sAMAc
Wscript.Echo strSA
objRecordSet.MoveNext
Loop
' Clean up.
objConnection.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
I can give you a one-liner Powershell script with the Quest Active directory tools cmdlets.
Get-QADGroup -Name *intranet* | Format-Table Name, email, DN
That will find all groups (Distro and security actually) and return the name, email and DN.