PowerShell Get-ADGroup
The Get-ADGroup PowerShell cmdlet is part of the Active Directory module for Windows PowerShell. It is used to retrieve information about Active Directory groups. Below are several examples and explanations on how to use Get-ADGroup.
Get-ADGroupMember with Recursive Membership
#Prompt for Active Directory group, list of membership and nested membership.
$ADGroup= Read-Host "Enter Group Name"
Try{
Get-ADGroupMember "$ADGroup" -ErrorAction Stop -Recursive | select Name, SamAccountName | Export-CSV "C:\Temp\$ADGroup.csv" -NoTypeInformation
}Catch{
Write-Host $_.Exception.Message
}
​
#Get-ADgroup | Like Name
#Query Active Directory for a list of groups with a name starting with App
​
Get-ADGroup -filter {Name -like "Parent*"} -Properties * | Select Name, Description, info
Get-ADGroup -Filter by Name Results
Get-ADGroup -Filter by Name
Get-ADGroup - Empty Active Directory Groups
<#
Empty Group Membership
Summary:
Import list of groups to check
Loop through list of groups
Get group membership assigned to var
Check member count, if zero export to file
​
Author: Scott Head
Date: 05/09/2022
Version: 1.0
#>
$GroupName= Get-Content "C:\temp\Group_Move\EmprtyGroupList.txt"
​
Foreach($Group in $GroupName){
$Member=Get-ADGroupMember $Group -ErrorAction Stop -Recursive | select Name, SamAccountName
if($Member.count -eq 0){$Group | Out-File C:\temp\Group_Move\EmptyGroups.txt -Append}
}