##########################################################################
# GET ALL ADMINISTRATORS GROUP MEMBERS - 1
$GroupName = "Administrators"
Get-ADGroupMember -Identity $GroupName | Select-Object name,distinguishedName,objectClass | Format-Table -AutoSize
### OUTPUT ###
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
# name distinguishedName objectClass
# ---- ----------------- -----------
# Domain Admins CN=Domain Admins,CN=Users,DC=rs,DC=local group
# Enterprise Admins CN=Enterprise Admins,CN=Users,DC=rs,DC=local group
# Administrator CN=Administrator,CN=Users,DC=rs,DC=local user
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
##########################################################################
# GET ALL ADMINISTRATORS GROUP MEMBERS - 2
$GroupName = "Administrators"
$Properties = "name", "distinguishedName", "objectClass", "SID"
Get-ADGroupMember -Identity $GroupName | Select-Object -Property $Properties | Format-Table -AutoSize
### OUTPUT ###
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
# name distinguishedName objectClass SID
# ---- ----------------- ----------- ---
# Domain Admins CN=Domain Admins,CN=Users,DC=rs,DC=local group S-1-5-21-1853119505-3322575478-2931423564-512
# Enterprise Admins CN=Enterprise Admins,CN=Users,DC=rs,DC=local group S-1-5-21-1853119505-3322575478-2931423564-519
# Administrator CN=Administrator,CN=Users,DC=rs,DC=local user S-1-5-21-1853119505-3322575478-2931423564-500
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
##########################################################################
# LOOP THROUGH MULTIPLE GROUPS (VERTICAL FORMATTING)
$GroupNames = @(
"Administrators"
"Account Operators"
"Server Operators"
)
$Properties = "name", "distinguishedName", "objectClass"
foreach ($GroupName in $GroupNames) {
$GetADGroupMember = Get-ADGroupMember -Identity $GroupName | Select-Object -Property $Properties
$GroupName + $GetADGroupMember
}
### OUTPUT ###
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
# name distinguishedName objectClass SID
# ---- ----------------- ----------- ---
# Domain Admins CN=Domain Admins,CN=Users,DC=rs,DC=local group S-1-5-21-1853119505-3322575478-2931423564-512
# Enterprise Admins CN=Enterprise Admins,CN=Users,DC=rs,DC=local group S-1-5-21-1853119505-3322575478-2931423564-519
# Administrator CN=Administrator,CN=Users,DC=rs,DC=local user S-1-5-21-1853119505-3322575478-2931423564-500
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------