Creating Microsoft 365 Groups can be done using various cmdlets available in the Microsoft Graph PowerShell module. However, the Invoke-MgGraphRequest cmdlet provides a versatile way to interact with the Microsoft Graph API directly, allowing you to create groups and configure them precisely according to your needs. This article will guide you through using Invoke-MgGraphRequest specifically for creating different types of Microsoft 365 groups, including Teams-enabled groups, security groups, and distribution groups.
Invoke-MgGraphRequest -Method POST -Uri 'https://graph.microsoft.com/v1.0/groups' -Body $params
$params = @{
"displayName" = "Project Team"
"mailEnabled" = $true
"mailNickname" = "projectteam"
"securityEnabled" = $false
"groupTypes" = @("Unified")
"visibility" = "Private"
}
Invoke-MgGraphRequest -Method POST -Uri 'https://graph.microsoft.com/v1.0/groups' -Body $params
This script creates a Microsoft 365 group named "Project Team" that is mail-enabled and private. The group is classified as "Unified," which means it includes collaboration features like a shared mailbox, calendar, and document library.
$params = @{
"displayName" = "Marketing Team"
"mailEnabled" = $true
"mailNickname" = "marketingteam"
"securityEnabled" = $false
"groupTypes" = @("Unified")
"visibility" = "Public"
"resourceProvisioningOptions" = @("Team")
}
Invoke-MgGraphRequest -Method POST -Uri 'https://graph.microsoft.com/v1.0/groups' -Body $params
This script creates a Microsoft 365 group named "Marketing Team" with Teams capabilities enabled. The group will have a connected Microsoft Teams team automatically created.
$params = @{
"displayName" = "IT Security Group"
"mailEnabled" = $false
"mailNickname" = "itsecuritygroup"
"securityEnabled" = $true
"groupTypes" = @()
}
Invoke-MgGraphRequest -Method POST -Uri 'https://graph.microsoft.com/v1.0/groups' -Body $params
This script creates a security group named "IT Security Group." Unlike a Microsoft 365 group, this group is used for assigning permissions and managing access to resources.
Note: Distribution groups cannot be created using the Graph PowerShell API. To create a distribution group, you need to use Exchange Online PowerShell as shown below.
# Connect to Exchange Online
Connect-ExchangeOnline -UserPrincipalName admin@yourdomain.com
# Create the Distribution Group
New-DistributionGroup -Name "Support Team" -Alias "supportteam" -PrimarySmtpAddress "supportteam@yourdomain.com"
This script creates a distribution group named "Support Team" using Exchange Online PowerShell. Distribution groups cannot be created directly through Microsoft Graph API, so this method is required.
Cause: This error typically occurs when required properties are missing or invalid values are provided.
Solution: Double-check that all required fields (displayName, mailNickname, etc.) are included and that values are formatted correctly. Ensure that the mailNickname is unique.
Cause: The user may not have sufficient permissions to create groups.
Solution: Verify that the executing user has the necessary roles, such as "Group Administrator" or a custom role with group creation permissions.
Cause: This occurs when the mailNickname is already in use.
Solution: Choose a unique mailNickname value for the new group.
The Invoke-MgGraphRequest cmdlet provides a flexible and powerful way to create various types of Microsoft 365 groups, offering greater control than standard cmdlets. Whether you're creating a standard Microsoft 365 group, a Teams-enabled group, a security group, or a distribution group, understanding the key parameters and possible errors will help you efficiently manage your Microsoft 365 environment.
Using this method, administrators can automate group creation, customize group configurations, and integrate these tasks into broader organizational processes. By leveraging the full power of the Microsoft Graph API, Invoke-MgGraphRequest ensures that your group's provisioning is both accurate and aligned with your organization's specific requirements.
© m365corner.com. All Rights Reserved. Design by HTML Codex