Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


AD and vbscript

Posted on 2011-05-05
Medium Priority
Last Modified: 2012-05-11
I would like to be able to modify the following script to also include all group descriptions.
Currently this script has been modified to get information from AD about all groups and the number of members. I would like for the script to also include the description from AD.

I am trying to output a list of all groups in AD, the number of members, and the description of each group.
'VBScript to output to text file the members of all groups
'V1.0 Neil Hobson (neil.hobson@silversands.co.uk)
'Last updated on 24/09/02
'v1.0 24/09/02 - Original code

On Error Resume Next
Set objArgs=wscript.Arguments

If objArgs(0)<>"-dn" Then
	wscript.echo "Dumping group membership using full DN..."
	wscript.echo "Dumping group membership using only first CN part..."
End If

'Stuff for creating output text file
Const OutputFile = ".\groupdump.txt"
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Wshshell = Wscript.CreateObject("Wscript.Shell")
Set Output = Fso.OpentextFile(OutputFile, 2, True)

Set ADSIRootDSE = GetObject("LDAP://RootDSE")
ADSINamingNC = ADSIRootDSE.Get("rootDomainNamingContext")
Set ADSIConnection = CreateObject("ADODB.Connection")
ADSIConnection.Provider = "ADsDSOObject"
ADSIConnection.Open "ADs Provider"

ADSIQueryText = "<LDAP://" & ADSINamingNC & ">;(&(objectCategory=group));name,distinguishedName;subtree"

Set ADSICommand = CreateObject("ADODB.Command")
Set ADSICommand.ActiveConnection = ADSIConnection
ADSICommand.CommandText = ADSIQueryText
ADSICommand.Properties("Page Size") = 100
ADSICommand.Properties("Timeout") = 60
ADSICommand.Properties("searchscope") = 2
ADSICommand.Properties("Cache Results") = False

Set ADSIResult = ADSICommand.Execute

Do While not ADSIResult.EOF

	Output.WriteLine "Group: " & ADSIResult.Fields("name").Value
	Output.WriteLine "==============================================================="

	Set GetDN = GetObject("LDAP://" & ADSIResult.Fields("distinguishedName").Value)
	strAllValues = GetDN.GetEx("member")
	iGroupCount = 0
	For each strValue in strAllValues
		If Len(strValue) = 0 Then
			Output.WriteLine "There are no members in this group."
			iGroupCount = iGroupCount + 1
			If objArgs(0)<>"-dn" Then
				Call Stripper(strValue)
				Output.WriteLine tmp
			End If
		End If
	Output.WriteLine "Total members in group: " & iGroupCount
	Set strAllValues = Nothing


wscript.echo "Operation has finished."

Function Stripper(StripperString)

pos = InStr(1, StripperString, "cn=", vbTextCompare)
If pos <> 0 Then
	tmp = Mid(StripperString, pos + 3)
	pos = InStr(tmp, ",")
	If pos <> 0 Then tmp = Mid(tmp, 1, pos - 1)
End If

End Function

Open in new window

Question by:kineticexpert
  • 2
LVL 65

Accepted Solution

RobSampson earned 500 total points
ID: 35703426
Hi, under this line:
      Set GetDN = GetObject("LDAP://" & ADSIResult.Fields("distinguishedName").Value)

add this:
      Output.WriteLine "Group Description: " & Join(GetDN.Description)



Author Comment

ID: 35717186
Output.WriteLine "Group Description: " & Join(GetDN.Description) did not work
however Output.WriteLine "Group Description: " & GetDN.Description    did
LVL 65

Expert Comment

ID: 35717200
Oh right....I forget whether that's an array or a string.   Sometimes it needs to be treated as an array.  Glad you got it working.  Is there anything else you need?


Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

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…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

572 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