Forum Discussion
teja1027 Hi, you can get the result using powershell , here under the script
# Import the Active Directory module
Import-Module ActiveDirectory# Specify the AD group names
$groupNames = @("Group1", "Group2", "Group3")# Create an array to store all group members
$allGroupMembers = @()# Iterate through each group name
foreach ($groupName in $groupNames) {
# Retrieve group members
$groupMembers = Get-ADGroupMember -Identity $groupName | Select-Object Name, SamAccountName# Add group members to the array
$allGroupMembers += $groupMembers
}# Export the group members to a CSV file
$csvPath = "C:\Path\to\output.csv"
$allGroupMembers | Export-Csv -Path $csvPath -NoTypeInformationWrite-Host "Export completed. The group members have been saved to: $csvPath"
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily.
- teja1027Copper ContributorThank you so much for the response. Can I import a text file with 200 groups inside the file and try running it? Can you help me where can I insert the file and run the script.
teja1027 here the script modified to read the groups from csv file
# Import the Active Directory module
Import-Module ActiveDirectory# Specify the path to the CSV file containing the group names
$csvPath = "C:\Path\to\groups.csv"# Read the group names from the CSV file
$groupNames = Import-Csv -Path $csvPath | Select-Object -ExpandProperty GroupName# Create an array to store all group members
$allGroupMembers = @()# Iterate through each group name
foreach ($groupName in $groupNames) {
# Retrieve group members
$groupMembers = Get-ADGroupMember -Identity $groupName | Select-Object Name, SamAccountName# Add group members to the array
$allGroupMembers += $groupMembers
}# Export the group members to a CSV file
$outputCsvPath = "C:\Path\to\output.csv"
$allGroupMembers | Export-Csv -Path $outputCsvPath -NoTypeInformationWrite-Host "Export completed. The group members have been saved to: $outputCsvPath"
Refer this, support in csv format: