# MgGraph - Connect to Entra AD with limited scope (example)
Connect-MgGraph -Scopes "Directory.Read.All", "Group.Read.All", "GroupMember.ReadWrite.All"
# MgGraph - Search for a group by name (examples)
Get-MgGroup -Filter "DisplayName eq 'GroupName'"
Get-MgGroup -Filter "startswith(DisplayName,'GroupNa')"
Get-MgGroup -Filter "DisplayName eq 'GroupNameA' or DisplayName eq 'GroupNameB'"
Get-MgGroup -Search 'Description:servergroup' -ConsistencyLevel eventual
# MgGraph - Collect the groupID of a group
$groupName = 'GroupName'
$groupId = Get-MgGroup -Filter "DisplayName eq '$groupName'" | Select-Object -ExpandProperty Id
$groupId
# MgGraph - Display the number of members of a group
$groupName = 'GroupName'
$groupObject = Get-MgGroup -Filter "displayName eq '$groupName'"
$groupId = $groupObject.Id
Get-MgGroupMemberCount -GroupId $groupId -ConsistencyLevel eventual
# MgGraph - Lookup a group by DisplayName
$displayName = 'Group Name'
Get-MgGroup -Filter "displayName eq '$groupName'"
# MgGraph - Lookup a group by DisplayName and show all properties
$displayName = 'Group Name'
Get-MgGroup -Filter "displayName eq '$groupName'" | Format-List
# MgGraph - List the Entra applications assigned to a group
$displayName = 'Group Name'
$groupId = (Get-MgGroup -Filter "DisplayName eq '$displayName'").Id
$assignedApplications = Get-MgGroupAppRoleAssignment -GroupId $groupId | Sort-Object ResourceDisplayName
$assignedApplications | Format-Table ResourceDisplayName,Id, AppRoleId, PrincipalDisplayName -AutoSize
# MgGraph - Count the members of an Entra group
$groupName = 'Group Name'
$groupId = Get-MgGroup -Filter "DisplayName eq '$groupName'" | Select-Object -ExpandProperty Id
(Get-MgGroupMember -GroupId $groupId -All).Count
# MgGraph - Display deleted groups
Get-MgDirectoryDeletedItemAsGroup -All
# MgGraph - Display all dynamic groups
Get-MgGroup -Filter "GroupTypes/any(x:x eq 'DynamicMembership')"
# MgGraph - Display all dynamic groups sorted on creation time
Get-MgGroup -Filter "GroupTypes/any(x:x eq 'DynamicMembership')" | Select-Object -Property DisplayName,CreatedDateTime | Sort-Object -Property CreatedDateTime
# MgGraph - Display all groups created between now and one year ago
Get-MgGroup -Filter "CreatedDateTime ge $((Get-Date).AddYears(-1).ToString("s"))Z" -ConsistencyLevel eventual -CountVariable Count
# MgGraph - Display all groups created between now and one year ago and that start with a specific string
Get-MgGroup -Filter "CreatedDateTime ge $((Get-Date).AddYears(-1).ToString("s"))Z and startsWith(Displayname,'xx-yyy-')" -ConsistencyLevel eventual -CountVariable Count
# MgGraph - Display all details of a group
Get-MgGroup -Filter "DisplayName eq 'GroupName'" | Format-List
Get-MgGroup -GroupId '00000000-0000-0000-0000-000000000000' | Format-List
# MgGraph - Display the membershiprule of a dynamic group
(Get-MgGroup -Filter "DisplayName eq 'GroupName'").MemberShipRule
# MgGraph - Display the membershiprule of a dynamic group
$groupName = 'GroupName'
Get-MgGroup -Filter "DisplayName eq '$groupName'" | Select-Object -Property 'MemberShipRule'
# MgGraph - Display the membershiprule of a dynamic group
$groupName = 'GroupName'
Get-MgGroup -Filter "DisplayName eq '$groupName'" | Select-Object -ExpandProperty 'MemberShipRule'
# MgGroup - Display deleted groups in Entra and display the output in a seperate window
Connect-MgGraph -Scopes Directory.Read.All, Group.ReadWrite.All
[array]$DeletedGroups = Get-MgDirectoryDeletedItemAsGroup -All
If ($DeletedGroups.count -eq 0) { Write-Host "No recoverable groups can be found - exiting"; break}
$Report = [System.Collections.Generic.List[Object]]::new(); $Now = Get-Date
ForEach ($Group in $DeletedGroups) {
[datetime]$DeletedDate = $Group.deletedDateTime
$PermanentRemovalDue = Get-Date($DeletedDate).AddDays(30)
$TimeUntilRemoval = $PermanentRemovalDue - $Now
$ReportLine = [PSCustomObject]@{
Group = $Group.displayName
Id = $Group.id
Deleted = $Group.deletedDateTime
PermanentDeleteOn = Get-Date($PermanentRemovalDue) -format g
DaysRemaining = $TimeUntilRemoval.Days }
$Report.Add($ReportLine)
}
$Report | Sort-Object {$_.PermanentDeleteOn -as [datetime]} | Out-GridView
# MgGraph - Display all members of a group by DisplayName and UPN, sorted by DisplayName and count the total
$groupDisplayName = 'entraGroupName'
$groupId = Get-MgGroup -Filter "DisplayName eq '$groupDisplayName'" | Select-Object -ExpandProperty 'Id'
$allMembers = Get-MgGroupMember -GroupId $groupId -All
$allMemberDisplayName = foreach ($member in $allMembers) {Get-MgUser -UserId $member.Id | Select-Object -Property 'Id','DisplayName','UserPrincipalName'}
$allMemberDisplayName | Sort-Object -Property 'DisplayName'
$allMemberDisplayName.Count
MgGraph – Group
•
Leave a Reply