How to Add Bulk Users to SharePoint Group using PowerShell
SharePoint groups allow members to access SharePoint content, such as documents, lists, and libraries. As a SharePoint admin often, you might be in the situation of adding multiple users to a SharePoint group. This blog will help you manage SharePoint Online group membership using PowerShell.
Before running the script/cmdlet, you must connect to SharePoint Online PowerShell.
Content:
- Add bulk users to the SPO group
- List all the SharePoint Online groups
- Get SharePoint Online group members
- Remove bulk users from the SPO group
To bulk import users from the CSV file and add those users to SharePoint Online group, you can use the following PowerShell script.
Connect-SPOService Import-CSV <FilePath> | foreach { $UPN=$_.UPN Write-Progress -Activity "Adding $UPN to SharePoint group..." Add-SPOUser –Site <SiteUrl> -Group <GroupName> -LoginName $UPN If($?) { Write-Host $UPN Successfully added -ForegroundColor Green } Else { Write-Host $UPN - Error occurred –ForegroundColor Red } }
In the above script, you can replace the following.
<FilePath> –>CSV file path.
<SiteUrl> –> Site URL (You can use the Get-SPOSite cmdlet to get the site url).
<GroupName> -SharePoint group name in which you want to add members.
The input CSV should follow the format below.
To list all the groups available in the specific site, use the ‘Get-SPOSiteGroup’ cmdlet.
Get-SPOSiteGroup –Site <SiteURL>
To view all the groups in SharePoint Online, run the following code snippet.
Get-SPOSite –Limit All | foreach { Write-Host Site: $_.url -Foregroundcolor Yellow Get-SPOSiteGroup –Site $_.url | Select LoginName }
The output lists all the sites and groups available on those sites.
To view SharePoint Online group members, you can run the ‘Get-SPOUser’ cmdlet with site URL and the respective group name.
Get-SPOUser –Site <SiteURL> -Group <GroupName>
To view all the groups in a specific site and their members, execute the below code.
Get-SPOSiteGroup -Site <SiteURL> | foreach {
Write-Host Group name: $_.LoginName -ForegroundColor Yellow
Get-SPOUser -Site <SiteURL> -Group $_.LoginName | select LoginName
}
After generating the SharePoint Online group membership report, admins can check for unnecessary permission grants. If required, admins can remove those members from the SharePoint Online group. You can use the following PowerShell script to bulk import users from the CSV file and remove those members from the SPO group.
Connect-SPOService Import-CSV <FilePath> | foreach { $UPN=$_.UPN Write-Progress -Activity "Removing member $UPN from SharePoint group..." Remove-SPOUser –Site <SiteUrl> -Group <GroupName> -LoginName $UPN If($?) { Write-Host $UPN Successfully removed -ForegroundColor Green } Else { Write-Host $UPN - Error occurred –ForegroundColor Red } }
Despite adding bulk users to SharePoint online groups, it is essential to monitor SPO groups. The Problem with PowerShell is that we need to use specific cmdlets to manage multiple SPO activities, which is tiresome and time-consuming! If you’re looking for something that provides better and more advanced reports surpassing the capabilities of native Office 365 reports, then I’ve got something to show you!
👋Say goodbye to complex PowerShell scripts or cmdlets! Introducing AdminDroid, where you can effortlessly monitor SharePoint Online users and groups with an easy-to-use, user-friendly interface.
SharePoint Site Groups Reports
- SharePoint Groups by Sites
- Security Groups by Sites
- Empty SharePoint Groups by Sites
- SharePoint Group Members
SharePoint Site Users Reports
- SharePoint Users by Sites
- SharePoint Site Admins
- SharePoint Guest Users
- SharePoint Site Owners
Moreover, SharePoint Online reporting tool comes like a piece of cake with SPO site info, document libraries, and site member details, etc. Using this handy tool, admins can get all the SharePoint Online details with in-depth details, graphical representation and advanced filters in a few clicks!
If you’re still thinking why AdminDroid is the ideal choice, let me give a compelling reason!
The AdminDroid SharePoint Online management tool provides 180+ reports on site permissions, external file sharing, SPO site ownerships, group memberships, etc., which helps to monitor SPO data effortlessly. In addition, AdminDroid provides 1800 all-inclusive reports and over 30 dashboards for Office 365 reporting, auditing, analytics, usage statistics, security & compliance, etc. Moreover, you can explore all the features and functionalities of AdminDroid with the free 15-day premium edition!
I hope this blog will help admins add and remove multiple members to SharePoint site groups and know about SPO group membership detail.