Export list of all Active Directory Security Groups with their Members

Learn how to easily export Active Directory Security Groups with their members to a CSV file in Windows PowerShell.

Here is a Script:

$Groups = Get-ADGroup -Properties * -Filter * -SearchBase "OU=Groups,DC=corp,DC=ourcompany,DC=Com"
Foreach($G In $Groups)
{
Write-Host $G.Name
Write-Host "-------------"
$G.Members
}

Here is another Script:

$Groups = Get-ADGroup -Properties * -Filter {GroupCategory -eq "Security"} -SearchBase "OU=Groups,DC=domain,DC=com"

Foreach($G In $Groups)

{

“+++++++++++++++++++++++” | Out-File c:\test\Report.txt -encoding ASCII -append

$G.Name | Out-File c:\test\Report.txt -encoding ASCII -append

“———————–” | Out-File c:\test\Report.txt -encoding ASCII -append

”  ” + $G.Members | Out-File c:\test\Report.txt -Encoding ASCII -append

”   ” | Out-File c:\test\Report.txt -Encoding ASCII -append

}

You may also like this - How to Get AD User’s Group Membership

Here is one more Script to produces additional information, such as all computer names with members:

Import-Module ActiveDirectory
$MemberList = New-Item -Type file -Force “C:\Scripts\GroupMembers.csv”
$Groups = Get-ADGroup -filter {GroupCategory -eq "Security"}
$Groups | ForEach-Object {
$Group = $_.Name
$Group | Out-File $MemberList -Encoding Unicode -Append
foreach ($member in Get-ADGroupMember $group) {$member.SamaccountName | Out-File $MemberList -Encoding Unicode -Append}
$nl = [Environment]::NewLine | Out-File $MemberList -Encoding ASCII -Append
}