How to create and manage Microsoft 365 groups with PowerShell

How to create and manage Microsoft 365 groups with PowerShell


Introduction:


Microsoft 365 Groups is a collaboration feature that allows users to work together and share resources such as calendars, files, and email messages. Microsoft 365 Groups can be created and managed using the Microsoft 365 admin center, but it can also be done using PowerShell. PowerShell provides a more efficient way to create and manage Microsoft 365 Groups, especially when you need to create a large number of groups or perform bulk operations.


In this article, we will discuss how to create and manage Microsoft 365 Groups using PowerShell.


Prerequisites:


Before we begin, you will need to ensure that you have the following:

  • Access to a Microsoft 365 tenant as a global administrator.
  • PowerShell installed on your computer.
  • Azure Active Directory PowerShell module installed.


Creating a Microsoft 365 Group using PowerShell:


To create a Microsoft 365 Group using PowerShell, follow the steps below:


1. Connect to Microsoft 365 using PowerShell: 


Open PowerShell on your computer and run the following command to connect to Microsoft 365:


  1. Connect-MsolService


Enter your global administrator credentials when prompted.


2. Create a new Microsoft 365 Group: 


To create a new Microsoft 365 Group, run the following command:


  1. New-UnifiedGroup -DisplayName "Test Group" -Alias "testgroup" -Description "This is a test group" -AccessType "Private"


This command will create a new private group named "Test Group" with an alias of "testgroup" and a description of "This is a test group". You can replace these values with your own.


3. Verify the creation of the group: 


To verify that the group was created successfully, run the following command:


  1. Get-UnifiedGroup -Identity "testgroup"


This command will return information about the group you just created.


Managing Microsoft 365 Groups using PowerShell:


Once you have created a Microsoft 365 Group using PowerShell, you can also manage it using PowerShell. Below are some common tasks that can be performed when managing Microsoft 365 Groups using PowerShell.


1. Add members to a group: 


To add members to a group, run the following command:


  1. Add-UnifiedGroupLinks -Identity "testgroup" -LinkType "Members" -Links "user1@domain.com", "user2@domain.com"


This command will add "user1@domain.com" and "user2@domain.com" to the "testgroup" as members. You can replace these values with your own.


2. Remove members from a group: 


To remove members from a group, run the following command:


  1. Remove-UnifiedGroupLinks -Identity "testgroup" -LinkType "Members" -Links "user2@domain.com"


This command will remove "user2@domain.com" from the "testgroup" as a member. You can replace these values with your own.


3. Change the group owner: 


To change the owner of a group, run the following command:


  1. Set-UnifiedGroup -Identity "testgroup" -ManagedBy "newowner@domain.com"


This command will change the owner of the "testgroup" to "newowner@domain.com". You can replace this value with your own.


4. Delete a group: 


To delete a group, run the following command:


  1. Remove-UnifiedGroup -Identity "testgroup"


This command will delete the "testgroup" from Microsoft 365. Note that this action cannot be undone, so use it with caution.


Conclusion:


In conclusion, PowerShell provides a powerful and efficient way to create and manage Microsoft 365 Groups. With PowerShell, you can quickly and easily create new groups, add or remove members, change the group owner, and delete groups when necessary. By using PowerShell to manage groups, you can save time and ensure that your Microsoft 365 Groups are set up and managed properly. With the above steps, you should now have a good understanding of how to create and manage Microsoft 365 Groups using PowerShell.


It's important to note that there are many other tasks you can perform using PowerShell to manage Microsoft 365 Groups. For example, you can modify the group settings, set up email addresses and aliases, and configure group policies. The possibilities are endless.


Using PowerShell to manage Microsoft 365 Groups can also be beneficial when working with large numbers of groups. PowerShell allows you to automate many of the tasks involved in creating and managing groups, which can save you time and effort.

In summary, PowerShell is a powerful tool for managing Microsoft 365 Groups. Whether you need to create a new group, add or remove members, change the group owner, or delete a group, PowerShell provides an efficient way to accomplish these tasks. By using PowerShell, you can ensure that your Microsoft 365 Groups are properly set up and managed.

    • Related Articles

    • Generate an Activity Report for Microsoft 365 Groups and Teams

      Introduction The activity reports available for Microsoft 365 groups and Teams can be beneficial for administrators in an organization. Microsoft 365 teams group activity reports provide insight into group activities, group workloads, group counts, ...
    • How to find unused Exchange Online mailboxes

      What are unused Exchange Online mailboxes and how to identify them? Unused Exchange Online mailboxes are user mailboxes which are currently not being used by their users. There are 3 ways in which we can identify if a mailbox is unused or not. They ...
    • Performing bulk operations in Microsoft 365 with PowerShell

      Performing bulk operations in Microsoft 365 with PowerShell, such as bulk adding users or modifying attributes, can be a very useful and efficient way to manage your organization's users and resources. PowerShell is a powerful command-line tool that ...
    • Create a mailbox database in Exchange Server

      Manually provisioning mailbox databases to new users can be arduous. However, administrators can turn to PowerShell scripts to create mailbox database easily. The below script will create a mailbox database in an Exchange Server with the name 'D10'. ...
    • Create a shared folder

      Provisioning and managing shared folders through the native Windows process is a pretty straightforward process. However, things can get quickly out of hand when you need to manage multiple shares across multiple computers. With PowerShell, you can ...