← script library

List Active Directory Group Members with PowerShell

Active DirectoryJanuary 5, 2025

Managing group memberships in Active Directory is crucial for maintaining security and ensuring proper access control. In this post, we will share a PowerShell script that helps you list all the members of a specified Active Directory group. This script can be especially helpful for administrators who need to review group memberships regularly. At ServerEngine, we strive to provide valuable tools for optimizing server management.

powershell
Import-Module ActiveDirectory

function Get-ADGroupMembers {
    param (
        [string]$groupName
    )
    try {
        $members = Get-ADGroupMember -Identity $groupName
        $members | Select-Object Name, SamAccountName, ObjectClass | Format-Table -AutoSize
    } catch {
        Write-Host "ERROR: Could not retrieve members for group: $groupName. Error: $_"
    }
}

Get-ADGroupMembers -groupName "YourGroupName"

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.

Ready when you are.

Try ServerEngine free for 7 days.