Haven’t done much scripting lately…..
The script for today is made for Ananth Kumar.
He asked me to make an extension to the “enumerate nested groups script” so that multiple nested groups can be enumerated based on an input file.
I did choose Excel for the input file so that i could reuse previous code.
Follow the next steps to run the script (no admin rights needed):
- find the distinguished names of the nested groups (adsiedit.msc)
- put them in an Excel sheet in the first column ans save the sheet as c:\temp\groups.xls
- open your favorite text editor
- copy and paste the script below into the editor (you can use the icons in the upper rights corner of the code)
- save the script (for example c:\temp\enumeratenestedgroupsfromexcelsheet.vbs)
- open a command prompt
- go to “c:\temp”
- give “cscript enumeratenestedgroupsfromexcelsheet.vbs” (without quotes) and enter
The script:
' Name : enumeratenestedgroupsfromexcelsheet.vbs
' Description : script to enumerate nested Active Directory groups from an Excel sheet
' Author : dirk adamsky - deludi bv
' Version : 1.0
' Date : 04-10-2011
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\temp\groups.xls")
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
strGroupDN = objExcel.Cells(intRow, 1).Value
If strGroupDN <> "" Then
wscript.echo strGroupDN
EnumNestedgroup "LDAP://" & strGroupDN
End If
intRow = intRow + 1
Loop
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
Function EnumNestedgroup(strGroupDN)
Set objGroup = GetObject(strGroupDN)
For Each objMember in objGroup.Members
If (LCase(objMember.Class) = "group") Then
EnumNestedgroup objMember.AdsPath
Else
Wscript.Echo objGroup.cn & " ; " & objMember.DisplayName & " ; " & objMember.Mail
End If
Next
Set objGroup = Nothing
End Function
When you have a modified version or problems/questions that you want to share please post it at the comments below.
Happy scripting.
Dirk Adamsky
