Create Microsoft 365 Group Using Microsoft Graph PowerShell

To create Microsoft 365 Groups using the Graph PowerShell SDK, you can follow these steps. The Microsoft Graph PowerShell SDK provides a direct way to interact with Microsoft Graph and automate tasks across Microsoft 365 services including the creation of groups.

Prerequisites

  • Install Microsoft Graph PowerShell SDK: If you haven't already, install the Graph PowerShell module using the following PowerShell command: Install-Module -Name Microsoft.Graph -Scope CurrentUser
  • Authentication: Before you can interact with Microsoft Graph, you need to authenticate by running the command: Connect-MgGraph -Scopes "Group.ReadWrite.All", "User.Read"
  • This will open a login prompt for you to enter your Microsoft 365 credentials. The scopes provided are required for creating and managing groups.

PowerShell Script for Creating a Microsoft 365 Group

Here’s the script for creating a Microsoft 365 Group using PowerShell:


Executing the PowerShell Script for Creating a Microsoft 365 Group

Navigate to the location where the PowerShell script for creating the Microsoft 365 Group exists and run the script as shown in the image. The details of the newly created Microsoft 365 Group gets displayed.



Important Notes


  • Mail Nickname: The MailNickname must be unique across your domain.
  • Permissions: Ensure authenticated user has permissions to create groups. Typically, this requires administrative privileges
  • Handling Errors: It's a good practice to add error handling when scripting to manage cases where the creation may fail (e.g., due to duplicate nicknames or insufficient permissions).

Adding User to Microsoft 365 Group

Here’s how you add a user to the group you created: you need to pass the user id to the -DirectoryObjectId parameter along with the Group's ID to the GroupId parameter of the New-MgGroupMember cmdlet as shown in the image.

Note: You can get the required user id by running the Get-MgUser cmdlet. You can get the required group id by running the Get-MgGroup cmdlet.



Adding Multiple Users to Microsoft 365 Group

Create an array of user ids, loop through the array and execute the New-MgGroupMember cmdlet. Ensure you pass the user ids to the -DirectoryObjectId parameter and the Group ID to -groupId parameter.

Note: Read Microsoft Documentation on Creating Microsoft 365 Group using Graph PowerShell for more information.


Related Articles:

Using Get-MgDirectoryRole in Graph PowerShell
Using Get-MgUserLicenseDetail in Graph PowerShell
Using Find-GraphMgCommand in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell

© m365corner.com. All Rights Reserved. Design by HTML Codex