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.
Install-Module -Name Microsoft.Graph -Scope CurrentUser
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.
Here’s the script for creating a Microsoft 365 Group using PowerShell:
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.
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.
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.
© m365corner.com. All Rights Reserved. Design by HTML Codex