A Guide to Manage SharePoint Online Users and Groups with PowerShell

A Guide to Manage SharePoint Online Users and Groups with PowerShell

SharePoint Online is a popular collaboration platform used by organizations to store, manage and share files, folders, and other resources. Although SharePoint has various built-in functions to manage users and groups, these settings may not be sufficient for all needs. Fortunately, PowerShell provides a powerful and flexible way to SharePoint Online reporting.

To manage SharePoint Online users and groups with PowerShell, admins must first install and connect to SharePoint Online PowerShell module using either the global administrator or SharePoint administrator account. In this blog, we will guide you through the steps to manage SharePoint Online users and groups using PowerShell effectively!

Get All SharePoint Sites Using PowerShell

You can get the list of SharePoint Online sites present in your tenant using the following cmdlet.

Get-SPOSite 

Get list of sites using PowerShell

You can also find and export all the SharePoint Online site collections and their required details using PowerShell.

Create a Group in SharePoint Online Using PowerShell

To create and add a new SharePoint Online group to a site, use the ‘New-SPOSiteGroup cmdlet.

New-SPOSiteGroup -Group <NewGroupName> -PermissionLevels <Level> -Site <SharePointSiteURL> 

Get list of sites using PowerShell

Update Group Properties in SharePoint Online Using PowerShell

The properties of an existing SharePoint Online group can be updated using the ‘Set-SPOSiteGroup‘ cmdlet.

For example,

Set-SPOSiteGroup -Identity <GroupName> -Site <SharePonitSiteURL> -PermissionLevelsToAdd <Level> 

In this example, the command adds another permission level to the existing group. Update Group Properties in SharePoint Online with PowerShell

Add a User to SharePoint Group Using PowerShell

To add a user to a SharePoint Online group on a site collection, you can use the ’Add-SPOUser‘ cmdlet.

Add-SPOUser -Group <GroupName> -LoginName <UPN> -Site <SharePointSiteURL> 

Add a User to SharePoint Group Uing PowerShell

To add multiple users to a SharePoint Online group efficiently, refer the PowerShell script to add bulk users to SharePoint Online Group.

Add User to Site Collection Administrators Group

To add a user to the site collection administrator group using PowerShell, you can utilize the ‘Set-SPOUser cmdlet.

Set-SPOUser -Site <SharePointSiteURL> -LoginName <UPN> -IsSiteCollectionAdmin $true 

Add a User to Site Collection Administrators Group Using PowerShell

Remove a User from a SharePoint Group

The ‘Remove-SPOUser‘ cmdlet can be used to remove a single Microsoft 365 user from a SharePoint Online site collection group.

Remove-SPOUser -LoginName <UPN> -Site <SharePointSiteURL> -Group <GroupName> 

You can remove a user from all groups they belong to by running the following cmdlet.

Get-SPOSite |ForEach {Remove-SPOUser -LoginName <UPN> -Site $_.Url}

And also, to bulk remove any unnecessary users from the groups,refer the PowerShell script to remove bulk users from SharePoint Online group.

Get SharePoint Online Group and Members with PowerShell

To list all the groups available in the specific site, use the ‘Get-SPOSiteGroup’ cmdlet.

Get-SPOSiteGroup –Site <SiteURL>

To view SharePoint Online group members, you can run the ‘Get-SPOUser’ cmdlet with site URL and the group name.

Get-SPOUser –Site <SiteURL> -Group <GroupName>

You can also refer our blog to view all the groups in SharePoint Online and to view the SharePoint Online group membership report.

Export SharePoint Online Users Using PowerShell

Using the below cmdlet, you can export the SharePoint Online user details for a specific site to a TXT or CSV file.

Get-SPOUser -Site <SharePointSiteURL> | Out-File <FilePath> -Append

Note: The Out-File cmdlet is used to write the output to a file. The -Append parameter appends the output to the file specified in the <FilePath> parameter, rather than overwriting it.

You can also export the SharePoint Online user details for all SharePoint sites to a TXT or CSV file by using the below cmdlet.

Get-SPOSite | ForEach {Get-SPOUser –Site $_.Url}| Out-File <FilePath> -Append

Grab Control Over SharePoint Online Membership Reports with AdminDroid!

Depend no more on complex PowerShell scripts or cmdlets! Easily monitor your organization’s collaboration environment without any technical expertise using AdminDroid’s SharePoint Online site users and groups reports. Enjoy a simple, intuitive interface that provides all the information you need!

Discover the SharePoint users and groups reports available in AdminDroid:

  • SharePoint Online Site Users Information – Lists SharePoint site users for every site and access levels such as site admins, guest users, and site owners
  • SharePoint Online Inactive Users – Shows the inactive users based on the last file access, last file sync, page access, external and internal file sharing.
  • SharePoint Online Site Collection Groups – Lists data about SharePoint Online groups, security groups, empty groups, and group memberships.

In addition, AdminDroid’s SharePoint Online groups and site collections auditing provides comprehensive reports on SPO group creation and modification. These reports include information on site collection admin changes, group membership changes, and external memberships. Moreover, AdminDroid SharePoint Online reporting provides advanced summary on SPO site collection, SPO users, inactive users, daily site usage, list & document libraries, etc. without the hassle of complex scripting!

AdminDroid SharePoint Online management tool helps to keep an eagle eye on SharePoint site permissions, external file sharing, site storage consumption, etc. to exempt data abuse in the organization.

SharePoint Groups Report by Site in AdminDroid

SharePoint Guest Users Report in AdminDroid

Looking for reasons to choose AdminDroid? We have the perfect answer for you.

In addition to SharePoint Management, AdminDroid offers a wealth of 1800+ pre-built reports for managing Microsoft 365 services including Azure AD, Security, Exchange Online, SharePoint Online, Microsoft Teams, Yammer, OneDrive, etc. Also, this tool helps you to easily schedule and export reports to analyze your organization’s performance. Download AdminDroid Office 365 reporting tool today and unlock the full potential of your Microsoft 365 environment!

We hope this article has provided an overall idea about how to manage SharePoint Online users and groups using PowerShell. If you have any questions or comments, feel free to share them in the comment section below.

A Guide to Manage SharePoint Online Users and Groups with PowerShell

by Thiraviam time to read: 4 min
0