###################################################################################################
# DEFINE A GROUP NAME AS A VARIABLE
$GroupName = "Administrators"
Get-ADGroup -Identity $GroupName
### OUTPUT ###
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
# DistinguishedName : CN=Administrators,CN=Builtin,DC=rs,DC=local
# GroupCategory : Security
# GroupScope : DomainLocal
# Name : Administrators
# ObjectClass : group
# ObjectGUID : 4efae99c-d4ec-4913-9fe0-b8c3a68089ba
# SamAccountName : Administrators
# SID : S-1-5-32-544
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
###################################################################################################
# USE A FILTER WITH A VARIABLE
$Filter = "Name -like '*Admin*'"
Get-ADGroup -Filter $Filter | Select-Object DistinguishedName, GroupCategory, GroupScope, Name, ObjectClass | Format-Table -AutoSize
### OUTPUT ###
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
# DistinguishedName GroupCategory GroupScope Name ObjectClass
# ----------------- ------------- ---------- ---- -----------
# CN=Administrators,CN=Builtin,DC=rs,DC=local Security DomainLocal Administrators group
# CN=Hyper-V Administrators,CN=Builtin,DC=rs,DC=local Security DomainLocal Hyper-V Administrators group
# CN=Storage Replica Administrators,CN=Builtin,DC=rs,DC=local Security DomainLocal Storage Replica Administrators group
# CN=Schema Admins,CN=Users,DC=rs,DC=local Security Universal Schema Admins group
# CN=Enterprise Admins,CN=Users,DC=rs,DC=local Security Universal Enterprise Admins group
# CN=Domain Admins,CN=Users,DC=rs,DC=local Security Global Domain Admins group
# CN=Key Admins,CN=Users,DC=rs,DC=local Security Global Key Admins group
# CN=Enterprise Key Admins,CN=Users,DC=rs,DC=local Security Universal Enterprise Key Admins group
# CN=DnsAdmins,CN=Users,DC=rs,DC=local Security DomainLocal DnsAdmins group
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
###################################################################################################
# USE A FILTER WITH A VARIABLE
$Filter = "Name -like 'Admin*'"
Get-ADGroup -Filter $Filter | Select-Object DistinguishedName, GroupCategory, GroupScope, Name, ObjectClass | Format-Table -AutoSize
### OUTPUT ###
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
# DistinguishedName GroupCategory GroupScope Name ObjectClass
# ----------------- ------------- ---------- ---- -----------
# CN=Administrators,CN=Builtin,DC=rs,DC=local Security DomainLocal Administrators group
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
###################################################################################################
# PASS MULTIPLE PARAMETERS AS VARIABLES
$GroupName = "Administrators"
$Properties = "Description", "Members"
Get-ADGroup -Identity $GroupName -Properties $Properties
### OUTPUT ###
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
# Description : Administrators have complete and unrestricted access to the computer/domain
# DistinguishedName : CN=Administrators,CN=Builtin,DC=rs,DC=local
# GroupCategory : Security
# GroupScope : DomainLocal
# Members : {CN=Domain Admins,CN=Users,DC=rs,DC=local, CN=Enterprise Admins,CN=Users,DC=rs,DC=local, CN=Administrator,CN=Users,DC=rs,DC=local}
# Name : Administrators
# ObjectClass : group
# ObjectGUID : 4efae99c-d4ec-4913-9fe0-b8c3a68089ba
# SamAccountName : Administrators
# SID : S-1-5-32-544
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
###################################################################################################
# USE A SCRIPT BLOCK FOR THE FILTER
$Filter = { Name -like "Admin*" }
Get-ADGroup -Filter $Filter
### OUTPUT ###
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
# DistinguishedName : CN=Administrators,CN=Builtin,DC=rs,DC=local
# GroupCategory : Security
# GroupScope : DomainLocal
# Name : Administrators
# ObjectClass : group
# ObjectGUID : 4efae99c-d4ec-4913-9fe0-b8c3a68089ba
# SamAccountName : Administrators
# SID : S-1-5-32-544
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
###################################################################################################
# LOOP THROUGH MULTIPLE GROUPS - 1
$GroupNames = @("Administrators", "Account Operators", "Server Operators")
foreach ($GroupName in $GroupNames) {
Get-ADGroup -Identity $GroupName | Select-Object Name, DistinguishedName, GroupCategory, GroupScope, ObjectClass, Description
}
### OUTPUT ###
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
# Name : Administrators
# DistinguishedName : CN=Administrators,CN=Builtin,DC=rs,DC=local
# GroupCategory : Security
# GroupScope : DomainLocal
# ObjectClass : group
# Description :
# Name : Account Operators
# DistinguishedName : CN=Account Operators,CN=Builtin,DC=rs,DC=local
# GroupCategory : Security
# GroupScope : DomainLocal
# ObjectClass : group
# Description :
# Name : Server Operators
# DistinguishedName : CN=Server Operators,CN=Builtin,DC=rs,DC=local
# GroupCategory : Security
# GroupScope : DomainLocal
# ObjectClass : group
# Description :
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
###################################################################################################
# LOOP THROUGH MULTIPLE GROUPS - 2
$GroupNames = @("Administrators", "Account Operators", "Server Operators")
foreach ($GroupName in $GroupNames) {
Get-ADGroup -Identity $GroupName | Select-Object Name, DistinguishedName
}
### OUTPUT ###
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
# Name DistinguishedName
# ---- -----------------
# Administrators CN=Administrators,CN=Builtin,DC=rs,DC=local
# Account Operators CN=Account Operators,CN=Builtin,DC=rs,DC=local
# Server Operators CN=Server Operators,CN=Builtin,DC=rs,DC=local
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
###################################################################################################
# LOOP THROUGH MULTIPLE GROUPS - 3
$GroupNames = @(
"Administrators"
"Account Operators"
"Server Operators"
)
foreach ($GroupName in $GroupNames) {
Get-ADGroup -Identity $GroupName | Select-Object Name, DistinguishedName
}
### OUTPUT ###
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
# Name DistinguishedName
# ---- -----------------
# Administrators CN=Administrators,CN=Builtin,DC=rs,DC=local
# Account Operators CN=Account Operators,CN=Builtin,DC=rs,DC=local
# Server Operators CN=Server Operators,CN=Builtin,DC=rs,DC=local
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
###################################################################################################
$GroupNames = @(
"Administrators"
"Account Operators"
"Server Operators"
)
$Properties = @(
"Name"
"DistinguishedName"
)
foreach ($GroupName in $GroupNames) {
Get-ADGroup -Identity $GroupName | Select-Object $Properties
}
### OUTPUT ###
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
# Name DistinguishedName
# ---- -----------------
# Administrators CN=Administrators,CN=Builtin,DC=rs,DC=local
# Account Operators CN=Account Operators,CN=Builtin,DC=rs,DC=loca
# Server Operators CN=Server Operators,CN=Builtin,DC=rs,DC=local
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
###################################################################################################