PowerShell: Export All Active Directory Groups to CSV

I recently needed to extract a list of all the groups in Active Directory and manipulate them in Excel.  This was easy enough to do in PowerShell.
##################################################################################
#                                                                                #
# List all groups in Active Directory. Save to your local Documents directory.   #
#                                                                                #
##################################################################################

$file = $env:USERPROFILE + "\Documents\grouplist.csv"
Get-ADGroup -Filter * | Select-Object samAccountName, DistinguishedName | Export-Csv -NoTypeInformation -LiteralPath $file

 

Comments are closed.