Need to edge out the competition for your dream job? Train for certifications today.
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
Dim intSize, objGroup, strUser, objUser, strHolder, strName, i, j
Dim objFSO, objOutputFile
intSize = 0
Set objGroup = GetObject("LDAP://CN=ADGroupName,OU=SubOU,OU=PrimaryOU,DC=root,DC=sub,DC=top")
If TypeName(objGroup.Member) = "Empty" Then
WScript.Echo "There are no members in " & objGroup.Name
ElseIf TypeName(objGroup.Member) = "String" Then
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
ReDim Preserve arrNames(intSize)
arrNames(intSize) = objUser.CN
intSize = intSize + 1
For i = (UBound(arrNames) - 1) to 0 Step -1
For j= 0 to i
If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
strHolder = arrNames(j+1)
arrNames(j+1) = arrNames(j)
arrNames(j) = strHolder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile("GroupMembers.csv")
For Each strName in arrNames
Set objOutputFile = Nothing
Set objFSO = Nothing
Set objUser = Nothing
Set objGroup = Nothing
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
$strUserName = "username"
$strUser = get-aduser $strUserName -Properties *
$strUser.memberof | Get-ADGroup | Select Name | Export-Csv -Path .\test.csv -NoTypeInformation
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment