widsnet.com
25Mar/131

Get members of an AD group

Get all members in an AD group, even recursive with -Recursive.

function Get-GroupMembers {
Param(
[parameter(Mandatory = $true)][string]$group,
[switch]$Recursive
)
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$groupObject = [System.DirectoryServices.AccountManagement.Principal]::FindByIdentity($ct,$group)
Return $groupObject.GetMembers($Recursive)
}
Comments (1) Trackbacks (0)
  1. You probably need to do a little more in order to resolve members and duplicate members in nested groups.


Leave a comment

No trackbacks yet.