PowerShell Quickie: Export AD Security Group Members to CSV

PowerShell Quickie: Export AD Security Group Members to CSV
Photo by Marcus Urbenz / Unsplash

PowerShell command for export security group member to .csv file


1. Open PowerShell run as administrator

  1. Open Active directory users and computer for check security group name to export members.
  1. Security group name "Degsign Folder".
  2. Use the below PowerShell command for retrive the members and export to file name Design.txt on D drive.
Get-ADGroupMember -Identity "Security Group Name" | Select-Object Name, SamAccountName | Export-Csv -Path "D:\DestinationFileName.csv" -NoTypeInformation -Encoding UTF8
Get-ADGroupMember -Identity "Design Folder" | Select-Object Name, SamAccountName | Export-Csv -Path "D:\Design Folder.csv" -NoTypeInformation -Encoding UTF8
  1. Export file will show.
  1. Open the .csv file view members.
  1. Can apply with multigroup each group for 1 csv file.
$Groups = @(
    "Design Folder", 
    "Group2", 
    "Group3", 
    "Group4", 
    "Group5", 
    "Group6", 
    "Group7", 
    "Group8", 
    "Group9",
    "Group10" 
)

foreach ($Group in $Groups) {
    Get-ADGroupMember -Identity $Group | 
    Select-Object Name, SamAccountName | 
    Export-Csv -Path "D:\$Group.csv" -NoTypeInformation -Encoding UTF8
}