As a System administrator, you have to very often query about the PowerShell active directory to list active directory groups and their description to search and migrate groups or users.
PowerShell Get-AdGroup cmdlet gets one or more ad groups based on search conditions. This command uses the filter
parameter to list all active directory groups, samaccountname, and descriptions about active directory groups.
In this article, we will discuss, how to list all AD groups and export them to csv file using PowerShell.
How to List AD Groups and Description with PowerShell
To list all ad groups and descriptions, use the Get-ADGroup command in PowerShell. The Get-AdGroup command uses the filter *
parameter to retrieve all active directory groups, descriptions, and properties.
Get-ADGroup -filter * -properties * |Select SAMAccountName, Description|Export-Csv adGroupList.csv
In the above PowerShell command, the Get-AdGroup cmdlet gets a list of all ad groups based on filter
* parameter and pass its output to the Select
command. The Select command selects samaccountname and description of ad group and pipes them to the Export-Csv command.
The Export-csv
cmdlet in PowerShell exports all ad groups to csv file format.
Cool Tip: Using PowerShell Get-ADComputer to find computer names in OU!
How to List All Active Directory Groups from OU
To get a list of active directory groups from a specific OU or domain, run the below command.
Get-ADGroup -filter * -properties * -searchbase "OU=Sales,DC=Shell,DC=Com"|Select SAMAccountName, Description|Export-Csv -Path D:\PowerShell\adGroupList.csv
In the above PowerShell command, the Get-ADGroup cmdlet uses the filter *
parameter to get the ad groups from the active directory. The Get-AdGroup command uses the -Searchbase
parameter to find ad groups from specified OU and pass its output to the second command.
The second command, selects samaccountname, description, and members and passes its output to the third command.
The third command, use Export-Csv
cmdlet to export ad groups to csv file format. The above commands list active directory groups from specified OU and export ad groups to a csv file.
Cool Tip: Using set-adgroup modify active directory group attributes PowerShell!
Conclusion
I hope the above article on how to use the Get-ADGroup cmdlet to list active directory groups, and descriptions, and export ad groups to a csv file is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.