VB Script…
To export users from Groups in AD
For work I had to export all the users from various AD groups, this was proving quite a task, but here is a work around if you ever need to do the same!
Just copy the code edit the sections to match your domain and save as a .VBS file
‘ Script to get group membership
strResult = “”
strCount = 0
strFile = “MemberOutput.csv”
set objFSO = createobject(”scripting.filesystemobject”)if objFSO.fileExists(strFile) then
set objLog = objFSO.opentextfile(strFile,2)
else
objFSO.createtextfile(strFile)
set objLog = objFSO.opentextfile(strFile,2)
end ifstrGroupDN = “CN=[EDIT],OU=[EDIT],OU=[EDIT],DC=[EDIT],DC=[EDIT],DC=[EDIT]“
Set objGroup = GetObject (”LDAP://” & strGroupDN)
objGroup.getInfoobjLog.writeline “”"Membership of: ” & strGroupDN & “”"” & vbcrlf
ProcessGroup strGroupDN
objLog.writeline “Total members: ” & strCount
objLog.writeline “Displayname,Distinguishedname” & vbcrlf
objLog.writeline strResultsub ProcessGroup(strGroupObject)
Set objGroup = GetObject (”LDAP://” & strGroupDN)
arrMemberOf = objGroup.GetEx(”member”)For each strGroupObj in arrMemberOf
set objObject = getObject(”LDAP://” & strGroupObj)
if objObject.objectcategory=”CN=Person,CN=Schema,CN=Configuration,DC=[EDIT],DC=[EDIT],DC=[EDIT]” then
strResult = strResult & “”"” & objObject.displayname & “”"” & “,”"” & objObject.distinguishedname & “”"” & vbcrlf
strCount = strCount + 1
else
ProcessGroup objObject.distinguishedname
end if
nextend sub
msgbox “Done”
If you get stuck let me know!


