Managing Teams and Groups
Microsoft 365 uses groups extensively. The Microsoft Graph PowerShell module lets you manage M365 Groups, Security Groups, and Teams from a single set of cmdlets.
Understanding Group Types
| Type | Purpose | Has Mailbox | Has Team Site |
|------|---------|-------------|---------------|
| M365 Group | Collaboration (email, files, calendar) | Yes | Yes |
| Security Group | Access control and licensing | No | No |
| Team | An M365 Group with Microsoft Teams enabled | Yes | Yes |
Key Concept: Every Microsoft Team is backed by an M365 Group, but not every M365 Group has a Team. When you create a Team, a group is created automatically.
Working with Groups
List and create groups using Get-MgGroup and New-MgGroup:
# Get all groups
Get-MgGroup -All
# Filter for a specific group
Get-MgGroup -Filter "displayName eq 'Engineering'"
# Create a new M365 Group
New-MgGroup -DisplayName "Design Team" -MailEnabled:$true `
-MailNickname "designteam" -SecurityEnabled:$false `
-GroupTypes "Unified"To create a security group instead, set -MailEnabled:$false, -SecurityEnabled:$true, and omit -GroupTypes.
Working with Teams
Retrieve Teams information and create channels:
# Get a specific team (requires the group ID)
$group = Get-MgGroup -Filter "displayName eq 'Engineering'"
Get-MgTeam -TeamId $group.Id
# Create a new channel
New-MgTeamChannel -TeamId $group.Id `
-DisplayName "Code Reviews" -Description "Channel for code review discussions"Managing Group Members
Add users to a group using New-MgGroupMember:
$group = Get-MgGroup -Filter "displayName eq 'Design Team'"
$user = Get-MgUser -Filter "userPrincipalName eq 'alex@contoso.com'"
New-MgGroupMember -GroupId $group.Id `
-DirectoryObjectId $user.IdTo view current members of a group:
Get-MgGroupMember -GroupId $group.Id | ForEach-Object {
Get-MgUser -UserId $_.Id | Select-Object DisplayName, UserPrincipalName
}Key Concept: Microsoft Graph cmdlets use object IDs (GUIDs) to reference resources, not display names. You typically look up the ID first with Get-MgGroup or Get-MgUser, then pass it to other cmdlets.
Exercises
Write the command to get all Microsoft 365 groups using the Microsoft Graph module.