Part of our Active Directory and Group Policy guides: every related guide in one place.
Powershell is an awesome tool and can help IT professionals in gathering information in a split second whereas otherwise it could take hours manually. We were recently asked to carry out a number of tasks for information gathering for annual housekeeping. The tasks were varied but were made up of information from Active Directory and Exchange. This meant that we could use Powershell and Exchange Management Shell to get this information quickly and efficiently. So, over the next few weeks we thought we would share our Powershell and Exchange Management Shell scripts on our blog here so that they can be reused by others. This is our first script but you can visit our Powershell category to find many more that we have posted on here in the past and the many more we will be posting over the next few weeks.Export all members of all AD Security Groups to CSV
For our first Powershell script, we were asked to provide a few list of all Active Directory Security Groups, their members and provide it in Excel format. So, below is the script we used to get the information and then export it to CSV file format.Get-ADGroup -filter "Groupcategory -eq 'Security' -AND GroupScope -ne 'DomainLocal' -AND Member -like '*'" |
foreach {
Write-Host "Exporting $($_.name)" -ForegroundColor Cyan
$name = $_.name -replace " ","-"
$file = Join-Path -path "C:\TGH" -ChildPath "$name.csv"
Get-ADGroupMember -Identity $_.distinguishedname -Recursive |
Get-ADObject -Properties SamAccountname,Title,Department |
Select Name,SamAccountName,Title,Department,DistinguishedName,ObjectClass |
Export-Csv -Path $file -NoTypeInformation
}
where:
- “C:\TGH” = CSV output directory
- $name.csv – this will automated create a filename, or you can amend this how you want it.
- Restart a service on multiple devices using Powershell
- Microsoft Windows & Server Evaluation, KMS & Product Keys: The Complete Free Guide (2026)
- Windows 10 Language Packs Offline Download (Full Guide 2026)
Feedback
If you have any questions or comments on this guide, please feel free to leave us a message below using our comments section.Gear We Recommend
Testing configs is easier with a dedicated admin machine set up right. Here’s the kit we use.
Browse our Windows Admin Toolkit picks on AmazonAs an Amazon Associate, TechyGeeksHome earns from qualifying purchases.
Discover more from TechyGeeksHome
Subscribe to get the latest posts sent to your email.