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

fig : Microsoft Graph PowerShell - Get-MgGraph - Getting all groups - formatting the output
fig : Microsoft Graph PowerShell - Get-MgGraph - Getting all groups - formatting the output

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 typeLeast privileged permissionsHigher privileged permissions
Delegated (work or school account)GroupMember.Read.AllGroup.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All, Group.Read.All
Delegated (personal Microsoft account)Not supported.Not supported.
ApplicationGroupMember.Read.AllGroup.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All, Group.Read.All
Table : Permissions required for working with Microsoft Groups

Let’s begin the show 🙂

Before executing Group related Microsoft Graph PowerShell CMDLETs, few steps need to perform

  • When we will execute Connect-MgGraph it will ask for user credentials as
fig : Microsoft Graph PowerShell – Signing for Microsoft Graph
  • As we will log in successfully, we are able to connect to Microsoft Graph
Microsoft PowerShell Graph - Executing Connect-MgGraph - returns the access token using MSAL (Microsoft Authentication Library)
fig : Microsoft PowerShell Graph – Executing Connect-MgGraph – returns the access token using MSAL (Microsoft Authentication Library)

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                                                                     

Microsoft Graph PowerShell - Get-MgGraph - Getting all groups in my organization
fig : Microsoft Graph PowerShell – Get-MgGraph – Getting all groups in my organization

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

Get-MgGroup | Format-List

Microsoft Graph PowerShell - Get-MgGraph - Getting all groups - formatting the output
fig : Microsoft Graph PowerShell – Get-MgGraph – Getting all groups – formatting the output

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')"

Microsoft Graph PowerShell - Get-MgGraph - Getting all groups which display name starts with keyword "Knowledge"  - using filter
fig : Microsoft Graph PowerShell – Get-MgGraph – Getting all groups which display name starts with keyword “Knowledge” – using filter

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  : {}

Microsoft Graph PowerShell - Get-MgGraph - Using Search - Getting all groups - where DisplayName contains keyword - "Knowledge"
fig : Microsoft Graph PowerShell – Get-MgGraph – Using Search – Getting all groups – where DisplayName contains keyword – “Knowledge”

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

Microsoft Graph PowerShell - Get-MgGraph - Using count variable - Getting the number of groups in my organization
fig : Microsoft Graph PowerShell – Get-MgGraph – Using count variable – Getting the number of groups in my organization

REFERENCES

Thanks for reading! Stay tuned for more articles on Microsoft Graph PowerShell!

HAPPY LEARNING AHEAD 🙂 LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading