This PowerShell script generates a report of user memberships for specified Active Directory groups. It is essential for system administrators to regularly monitor group memberships to ensure appropriate access controls and security policies are enforced. By integrating this report with ServerEngine, organizations can streamline their user management processes and enhance overall security posture by keeping group memberships in check.
powershell
param (
[string[]]$groupNames = @("Domain Admins", "Enterprise Admins"),
[string]$outputFilePath = "C:\ADGroupMembershipReport.csv"
)
# Initialize an array to store group membership details
$groupMembershipReport = @()
foreach ($group in $groupNames) {
# Get the group object
$adGroup = Get-ADGroup -Identity $group -ErrorAction SilentlyContinue
if ($adGroup) {
# Get the members of the group
$members = Get-ADGroupMember -Identity $adGroup | Select-Object Name, SamAccountName, ObjectClass
foreach ($member in $members) {
$groupMembershipReport += [PSCustomObject]@{
GroupName = $group
MemberName = $member.Name
SamAccountName = $member.SamAccountName
ObjectClass = $member.ObjectClass
}
}
} else {
Write-Output "Group '$group' not found in Active Directory."
}
}
# Export the group membership report to a CSV file
$groupMembershipReport | Export-Csv -Path $outputFilePath -NoTypeInformation
Write-Output "Active Directory group membership report has been saved to $outputFilePath."Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Active Directory
Active Directory User Onboarding with PowerShell
2026-08-17Active Directory User Offboarding with PowerShell
2026-08-17Disable an Active Directory User with PowerShell
2026-08-17Enable an Active Directory User with PowerShell
2026-08-17Unlock an Active Directory Account with PowerShell
2026-08-17Reset an Active Directory Password with PowerShell
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.