PowerShell script block to list all members from a list of groups

This will loop through the groups that it finds that match the “like” section of the script, then output the users from each group with headings to separate. The formatting could be cleaned up a bit on output, but…….meh it works.

$groups = Get-ADGroup -filter {SamAccountName -like "*GROUPNAMEHERE*"}
For ($i=0; $i -lt $groups.Length; $i++){
write-host ------------------------
Get-ADGroupMember $groups[$i] | select SamAccountName
write-host ************************

Enumerate users in an Active Directory group

Here is a little script that I ran accross today to help with dumping the members of an AD group into a text file. Edit as you see fit for your situation. Best to copy and paste it from here. If you manually type it, watch out for the word wrap.

'Script begins here
Dim objGroup, objUser, objFSO, objFile, strDomain, strGroup, Domain, Group
'Change DomainName to the name of the domain the group is in
strDomain = Inputbox ("Enter the Domain name", "Data needed", "Default domain name")
'Change GroupName to the name of the group whose members you want to export
strGroup = InputBox ("Enter the Group name", "Data needed", "Default group name")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'On the next line change the name and path of the file that export data will be written to.
Set objFile = objFSO.CreateTextFile("C:\utils\" & strGroup & " - Members.txt")
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
For Each objUser In objGroup.Members
'objFile.WriteLine objUser.Name & " - " & objUser.Class
objFile.WriteLine objUser.Name
Set objFile = Nothing
Set objFSO = Nothing
Set objUser = Nothing
Set objGroup = Nothing
Wscript.Echo "Done"
Wscript.Echo "Please check the c:\utils\ for your output file"