Solved

Need script to generate a list of all of the groups in AD with the word Intranet in it

Posted on 2011-02-18
3
302 Views
Last Modified: 2012-06-27

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?
0
Comment
Question by:wrkstat
3 Comments
 
LVL 57

Accepted Solution

by:
Mike Kline earned 250 total points
ID: 34927300
You can use a tool like adfind  http://www.joeware.net/freetools/tools/adfind/index.htm

adfind -default -f "&(objectcategory=group)(name=*intranet*)"  name samacountname

Let me know how that works.

Thanks

Mike
0
 
LVL 14

Expert Comment

by:athomsfere
ID: 34927333
Does it have to be VBScript?

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.
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34927911
You can also try this Vbscript

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)(name=*intranet*)"
'List all attributes you will require
strAttributes = "distinguishedName,sAMAccountName"
'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("distinguishedName")
    strSA = objRecordSet.Fields("sAMAccountName")
    Wscript.Echo strSA
    objRecordSet.MoveNext
Loop
' Clean up.
objConnection.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This article runs through the process of deploying a single EXE application selectively to a group of user.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question