Forum Discussion
Tring to pull the users from Azure AD Groups
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 -NoTypeInformation
Write-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.
- eliekarkafyMay 26, 2023MVP
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"
- ritikatguptaOct 16, 2024Copper Contributor
eliekarkafy
I tried using a script, and it worked, but I also want to include group name information, showing which user belongs to which group.