Microsoft 365 : Microsoft Graph PowerShell tutorial – Part 7 – Exploring Groups PowerShell CMDLETs

Hi All,
Greetings for the day!
Continuing on my favorite topic – Microsoft Graph Powershell.
Today we will discussing again important CMDLET – Get-MgGroup
Use : Get-MgGroup PowerShell CMDLET is used to get the group object their properties and relationship in between
Permissions required to work with Microsoft Groups using Microsoft Graph PowerShell
| Permission type | Least privileged permissions | Higher privileged permissions |
|---|---|---|
| Delegated (work or school account) | GroupMember.Read.All | Group.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All, Group.Read.All |
| Delegated (personal Microsoft account) | Not supported. | Not supported. |
| Application | GroupMember.Read.All | Group.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All, Group.Read.All |
Let’s begin the show 🙂
Before executing Group related Microsoft Graph PowerShell CMDLETs, few steps need to perform
- Make sure Microsoft Graph PowerShell SDK is installed. We have very detailed article for installing Microsoft Graph PowerShell SDK and to begin with Microsoft PowerShell Graph – Microsoft 365 : PowerShell – Microsoft Graph PowerShell tutorial – Part 1 – https://knowledge-junction.in/2023/08/30/microsoft-365-powershell-microsoft-graph-powershell-tutorial-part-1/
- Once Microsoft Graph PowerShell SDK is installed, next step is to connect to Microsoft Graph using CMDLET – Connect-MgGraph with appropriate scope. We have detailed article for Connect-MgGraph – Microsoft 365 : PowerShell – Microsoft Graph PowerShell tutorial – Part 2 – exploring Connect-MgGraph with couple of scenarios – https://knowledge-junction.in/2024/01/18/microsoft-365-powershell-microsoft-graph-powershell-tutorial-part-2-exploring-connect-mggraph-with-couple-of-scenarios/
- When we will execute Connect-MgGraph it will ask for user credentials as

- As we will log in successfully, we are able to connect to Microsoft Graph

Now we are ready to execute Microsoft Graph PowerShell CMDLETs
Example 1 : Get all Groups of my organization
CMDLET
#Once connected, execute the CMDLET to get all groups
Get-MgGroup
Output:
Id DisplayName Description
-- ----------- -----------
0f841e40-52a6-4e16-80fd-c53c5070edab SecurityGroupDemo
0fc405be-2de1-4089-a870-f46f24bfd9ec ALNG-W-CZTPAHGA01-AP
218800be-4d7b-4f7d-9e4b-57ec94271cb9 SecurityGroup2
33dc6486-ea92-4f23-b815-6d0fdb7b3590 KnowledgeJunctionSecurityGroup KnowledgeJunctionSecurityGroup
49ab2aca-ef4c-438d-bb99-69682e87df21 Library Assist
50a3b708-828a-4e68-925b-6e63a833dfc3 Teams Creators Members of this group only allow to create the Teams / M...
58dc164d-f135-41f7-b8a5-26d27b7deccd Azure ATP knowledgejunction1 Administrators
5f3ca8c4-2692-49d9-b7b7-764db67d5f71 office365_governance
7a8f960b-787d-4de3-9bcf-62d0bd9a900d Knowledge Junction Distribution list for Knowledge Junction
cca998ff-960b-48af-8687-153361923b83 M365Philly
cf6612da-1f85-4b41-8134-10d70187e7b0 Azure ATP knowledgejunction1 Viewers
ed1922be-afab-41c9-a080-bf530c16f903 Exploring Discover feature Exploring Discover feature
fd340202-d34d-4d0e-9cf8-51057a763b51 Azure ATP knowledgejunction1 Users

We could format the output of CMDLET using Format-List as
Get-MgGroup | Format-List

Example 2 : Get all the groups where Display Name starts with “Knowledge” keyword using -Filter
#using filter - Getting all groups where displat name starts with "Knoweldge" keyword
Get-MgGroup -Filter "startsWith(DisplayName, 'Knowledge')"

Example 3 : Get all the groups where Display Name contains with “Knowledge” using -Search
#using search - Get all the groups where DisplayName contains the word - 'Knowledge'
Get-MgGroup -ConsistencyLevel eventual -Search '"DisplayName:Knowledge"' | Format-List Id, DisplayName, Description, GroupTypes
Output :
Id : 33dc6486-ea92-4f23-b815-6d0fdb7b3590
DisplayName : KnowledgeJunctionSecurityGroup
Description : KnowledgeJunctionSecurityGroup
GroupTypes : {}
Id : 58dc164d-f135-41f7-b8a5-26d27b7deccd
DisplayName : Azure ATP knowledgejunction1 Administrators
Description :
GroupTypes : {}
Id : 7a8f960b-787d-4de3-9bcf-62d0bd9a900d
DisplayName : Knowledge Junction
Description : Distribution list for Knowledge Junction
GroupTypes : {}
Id : cf6612da-1f85-4b41-8134-10d70187e7b0
DisplayName : Azure ATP knowledgejunction1 Viewers
Description :
GroupTypes : {}
Id : fd340202-d34d-4d0e-9cf8-51057a763b51
DisplayName : Azure ATP knowledgejunction1 Users
Description :
GroupTypes : {}

Example 4 : Get count of all the groups from my organization
To get the count we need to use count variable
#Get count of all the groups in my tenant - we need to use count variable
Get-MgGroup -ConsistencyLevel eventual -Count groupsCount

REFERENCES
- Get-MgGroup – https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.groups/get-mggroup?view=graph-powershell-1.0
- Microsoft Graph PowerShell tutorial – https://knowledge-junction.in/category/technology-articles/m365/microsoft-graph/microsoft-graph-powershell/
Thanks for reading! Stay tuned for more articles on Microsoft Graph PowerShell!
HAPPY LEARNING AHEAD 🙂 LIFE IS BEAUTIFUL 🙂

You must be logged in to post a comment.