Managing Office 365 Group Membership with PowerShell

Overview

Collaborating with coworkers and sharing content, chats, and files is easy with Office 365 Groups. In particular, if there are a lot of groups and users to manage, managing the membership of these groups might take a lot of time. Office 365 Group membership can be managed by administrators using PowerShell to speed up the procedure. In this post, we’ll look at using PowerShell to extract an Office 365 Group’s membership list, export it to a CSV file, and add or remove users from the group.

Getting Office 365 Group Membership with PowerShell

To retrieve the membership of an Office 365 Group, administrators can use the following PowerShell command:

Get-UnifiedGroupLinks -Identity "<Group Name>" -LinkType Member

Where “<Group Name>” is the name of the Office 365 Group whose membership you want to retrieve. The Get-UnifiedGroupLinks cmdlet retrieves information about the membership of a group, including the type of link and the members themselves. The -LinkType Member switch specifies that we want to retrieve only the members of the group.

Exporting Office 365 Group Membership to CSV

Once you have retrieved the membership of an Office 365 Group, you may want to export the list to a CSV file for further analysis or reporting purposes. To export the list to a CSV file, administrators can use the following PowerShell command:

Get-UnifiedGroupLinks -Identity "<Group Name>" -LinkType Member | Export-Csv -Path "C:\GroupMembers.csv" -NoTypeInformation

Where “C:\GroupMembers.csv” is the path and file name of the CSV file where the membership information will be exported. The -NoTypeInformation switch disables the addition of type information to the output file.

Adding and Removing Users from an Office 365 Group with PowerShell

To add a user to an Office 365 Group, administrators can use the following PowerShell command:

Add-UnifiedGroupLinks -Identity "<Group Name>" -Links "<User Principal Name>" -LinkType Member

Where “<Group Name>” is the name of the Office 365 Group, and “<User Principal Name>” is the user principal name of the user you want to add to the group. The Add-UnifiedGroupLinks cmdlet adds a link to a group, in this case, adding the specified user as a member of the group.

To remove a user from an Office 365 Group, administrators can use the following PowerShell command:

Remove-UnifiedGroupLinks -Identity "<Group Name>" -Links "<User Principal Name>" -LinkType Member

Where “<Group Name>” is the name of the Office 365 Group, and “<User Principal Name>” is the user principal name of the user you want to remove from the group. The Remove-UnifiedGroupLinks cmdlet removes a link from a group, in this case, removing the specified user as a member of the group.

Office 365 Groups offer a fantastic way to work together and share files, chats, and content with coworkers. To manage the membership of these groups, administrators can utilize PowerShell, which makes it simpler to add or remove users, obtain membership information, and export membership information to a CSV file. Administrators can save time and guarantee consistency by using PowerShell to automate these operations.

Leave a Reply

Your email address will not be published. Required fields are marked *