This VBscript will export the members of the specified AD group and then save and display in excel. Tested on Windows 10 and Windows 2008 functional domain.
'==========================================================================
'GetGroupMembers.vbs
'Created by Timothy Bourne
'http://www.imric.co.uk
'Last Modified: 27/07/2015
'==========================================================================
'This VBscript will export the members of the specified AD group and
'then save and display in excel.
'==========================================================================
Option Explicit
'On Error Resume Next
Dim strGroup
Dim objFSO, objOutfile, objGroup, objMember, objShell
strGroup = InputBox("Please enter the group name:")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFSO.CreateTextFile(strGroup & ".csv")
Set objGroup = GetObject("LDAP://cn=" & strGroup & ",OU=Groups,OU=Site,DC=Domain,DC=Name")
objOutFile.WriteLine "Group Name: " & objGroup.SAMAccountName
objOutFile.WriteLine objGroup.Info
objOutFile.WriteLine "Members:"
For Each objMember in objGroup.Members
objOutFile.WriteLine "," & objMember.cn
Next
WScript.Echo "Exported the group: "& strGroup
Set objShell = CreateObject("WScript.Shell")
objShell.run ("Excel" & " """ & strGroup & ".csv""")
No comments:
Post a Comment