- Follow via:
- RSS
- Email Alert
Question
0
Votes
export to excel the list of members in a specific security group thru VBS
VB Script help in collecting the Data from AD Security group
18th Dec 2008
Answers (2)
0
Votes
AD uses LDAP
19th Dec 2008
0
Votes
Try this script
'Script created on 5 December 2007
'Prompts user to enter friendly name of a group and then dumps
'the display names of the members of that group to both screen and
'a text file on the root of Where the vbs file resides.
'******************************DECLARATIONS**********************************
Const ADS_SCOPE_SUBTREE = 2
Const ADS_CHASE_REFERRALS_SUBORDINATE = &H20
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set DataList = CreateObject("System.Collections.ArrayList")
dim sCurPath
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") & "\"
'WScript.Echo sCurPath
strGroupName = GetGroup
'WScript.Echo GetGroup
'******************************FUNCTIONS**********************************
Function Output(group)
group.GetInfo
arrMemberOf = group.GetEx("member")
For Each strMember in arrMemberOf
strLDAPPath = "LDAP://" & strMember
Set objUser = GetObject(strLDAPPath)
DataList.Add objUser.DisplayName
Next
DataList.Sort()
'strOutputPath = "c:\" & group.DisplayName & ".txt"
strOutputPath = sCurPath & right(group.name,(len(group.name)-3)) & ".txt"
wscript.echo strOutputPath
Set objOutput = objFSO.CreateTextFile(strOutputPath)
WScript.Echo "Members of " & group.name
For Each strItem in DataList
intTotalMembers = intTotalMembers + 1
objOutput.WriteLine strItem
WScript.Echo strItem
Next
WScript.Echo
WScript.Echo intTotalMembers & " total members of " & group.Name & "."
objFinal = MsgBox("File has been saved as " & strOutputPath,vbOKOnly,"File Information")
End Function
Function GetGroup
strGroup = InputBox("Enter the group name.","Enter Name")
If strGroup = "" Then
WScript.Quit
Else
Main(strGroup)
End If
End Function
Function Main(group)
On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Chase referrals") = ADS_CHASE_REFERRALS_SUBORDINATE
objCommand.CommandText = _
"SELECT distinguishedName FROM 'GC://DC=DOMAIN,DC=COM' WHERE " _
& "objectClass = 'group' AND Name = '" & group & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
If err.Number .vbs //nologo
'Prompts user to enter friendly name of a group and then dumps
'the display names of the members of that group to both screen and
'a text file on the root of Where the vbs file resides.
'******************************DECLARATIONS**********************************
Const ADS_SCOPE_SUBTREE = 2
Const ADS_CHASE_REFERRALS_SUBORDINATE = &H20
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set DataList = CreateObject("System.Collections.ArrayList")
dim sCurPath
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") & "\"
'WScript.Echo sCurPath
strGroupName = GetGroup
'WScript.Echo GetGroup
'******************************FUNCTIONS**********************************
Function Output(group)
group.GetInfo
arrMemberOf = group.GetEx("member")
For Each strMember in arrMemberOf
strLDAPPath = "LDAP://" & strMember
Set objUser = GetObject(strLDAPPath)
DataList.Add objUser.DisplayName
Next
DataList.Sort()
'strOutputPath = "c:\" & group.DisplayName & ".txt"
strOutputPath = sCurPath & right(group.name,(len(group.name)-3)) & ".txt"
wscript.echo strOutputPath
Set objOutput = objFSO.CreateTextFile(strOutputPath)
WScript.Echo "Members of " & group.name
For Each strItem in DataList
intTotalMembers = intTotalMembers + 1
objOutput.WriteLine strItem
WScript.Echo strItem
Next
WScript.Echo
WScript.Echo intTotalMembers & " total members of " & group.Name & "."
objFinal = MsgBox("File has been saved as " & strOutputPath,vbOKOnly,"File Information")
End Function
Function GetGroup
strGroup = InputBox("Enter the group name.","Enter Name")
If strGroup = "" Then
WScript.Quit
Else
Main(strGroup)
End If
End Function
Function Main(group)
On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Chase referrals") = ADS_CHASE_REFERRALS_SUBORDINATE
objCommand.CommandText = _
"SELECT distinguishedName FROM 'GC://DC=DOMAIN,DC=COM' WHERE " _
& "objectClass = 'group' AND Name = '" & group & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
If err.Number .vbs //nologo
9th Oct
Replies
The OP gave up years ago, or has since found another line of work. Zombies should not be awakened.
wizard57m-cnet
9th Oct

































