Get All Members of An Active Directory Security Group in SharePoint

Requirement: Get Active Directory Group Membership to list all users of an AD Group.

PowerShell to Get Members of an Active Directory Group in SharePoint
Although you can get AD group members using Get-ADGroupMember cmdlet to query the Active Directory, Here is the native way to get users of a Active Directory group in SharePoint.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Define Variables
$WebURL = ""
$ADGroupName = "Crescent\Deal_Pipeline"

#Get the Web
$web = Get-SPWeb $WebURL

#Resolve the AD Group in SharePoint
$ADGroup = $web.EnsureUser($ADGroupName)
$ReachedMax = $False

#Get All Users of the AD Group
$Users = [Microsoft.SharePoint.Utilities.SPUtility]::GetPrincipalsInGroup($web, $ADGroup, 10, [ref]$ReachedMax) 

$Users | Select DisplayName, LoginName, Email, JobTitle
This PowerShell script gets you all users of a given AD group.

Get All Members of the AD Group using PowerShell:
This time, let use the PowerShell cmdlet Get-ADGroupMember to list all members from a AD security group.
$ADGroup = "Crescent\Palo Alto"

#Extract AD Group Name
$ADGroupName = $ADGroup.Substring($ADGroup.IndexOf("\") + 1)

#Get All Members of the AD Group
$GroupMembers = Get-ADGroupMember -Identity $ADGroupName -Recursive

Write-host "Total Members Found:"$GroupMembers.Count

#Get Display Name, Member Type and SamAccountName Properties
$GroupMembers | Select-Object @{Name="Display Name";Expression={$_.Name}},
                @{Name="Account";Expression={$_.SamAccountName}} | Format-Table -AutoSize 

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.