0

Is there a way to add in bulk users to share point online Permission Groups? i would like to add in multiple users into multiple groups or single group in SharePoint Online, Any Help will be appreciated.

Thank you

2 Answers 2

0

You can store the users and site/group information into a csv file, then use CSOM PowerShell cmdlets to call the file and add users into SharePoint groups.

A demo for your reference:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Import-SPOUserFromCSV($CSVFile)
{ 
    #Get data from CSV
    $UserData = Import-CSV $CSVFile

    #Get Credentials to connect
    $Cred = Get-Credential

    ForEach($Row in $UserData)
    {
        #Get Data from CSV
        $SiteURL = $Row.SiteURL
        $GroupName= $Row.GroupName
        $UserAccount = $Row.UserAccount

        Try {
            #Setup the context
            $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
            $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

            #Get the Web and Group
            $Web = $Ctx.Web
            $Group= $Web.SiteGroups.GetByName($GroupName)

            #Resolve the User
            $User=$web.EnsureUser($UserAccount)

            #Add user to the group
            $Result = $Group.Users.AddUser($User)
            $Ctx.Load($Result)
            $Ctx.ExecuteQuery()

            write-host  -f Green "User '$UserAccount' has been added to '$GroupName' in Site '$SiteURL'"
        }
        Catch {
            write-host -f Red "Error Adding user to Group!" $_.Exception.Message
        }
    }
}

#Call the function
Import-SPOUserFromCSV "C:\Temp\UserData.csv"

More information:
SharePoint Online: Bulk Import Users to Groups from a CSV File using PowerShell
SharePoint Online: PowerShell to Add User to Group

9
  • Tried this one, Multiple errors with this Mar 27, 2020 at 7:15
  • Error Adding user to Group! A constructor was not found. Cannot find an appropriate constructor for type Microsoft.SharePoint.Client.ClientContext. Mar 27, 2020 at 7:20
  • Did you download SharePoint Online Client Components SDK? If not, download it then try again. microsoft.com/en-us/download/details.aspx?id=42038
    – Kally_MSFT
    Mar 27, 2020 at 7:35
  • Just downloaded it and installed it, Run again? Mar 27, 2020 at 7:38
  • yes, have a try and let's know the result.
    – Kally_MSFT
    Mar 27, 2020 at 7:40
0

Go to the "Microsoft 365 Admin Center" home page. https://admin.microsoft.com/Adminportal/Home?source=applauncher#/users

Then click on the "Active Users" link from the left panel.

Click on the "Add Multiple users" from the user dashboard report.

Download the sample CSV template.

Update the CSV the user details.

Upload the CSV file where you have multiple users. Example below:

How to Add Multiple Users in SharePoint Online Office 365

Add multiple users to SharePoint Online Group using PowerShell and CSV file:

Using the below PowerShell script, we can add multiple users into the SharePoint Online group:

#Connection paramaters
$AdminURL = "https://Crescent-admin.sharepoint.com/"
$AdminName = "[email protected]"
$CSVFile="C:\UsersToAdd.csv"

#User Names Password to connect
$Password = Read-host -assecurestring "Enter Password for $AdminName"
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Password

#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential

#add multiple users to sharepoint online group powershell - Import Users from CSV
Import-Csv $CSVFile | ForEach-Object { Add-SPOUser -Site $_.SiteURL -Group $_.GroupName -LoginName $_.UserAccount}

Source:

SharePoint Online: PowerShell to Add User to Group

4
  • i am looking for a way to add the user's in SharePoint Permission groups, I have created permission groups in share point online website within the site and i would like to import users to the group directly may be using a csv or any other way Mar 27, 2020 at 7:00
  • Ohh...updated the answer and added PowerShell script
    – SP 2022
    Mar 27, 2020 at 7:09
  • My account has 2FA configured will this work with that? Mar 27, 2020 at 7:22
  • Earlier, MFA enabled account was not supporting now it supports. However, if you face any issues to connect, for time being you can disable MFA for your account, and after executing the script, you can enable it back. The recommendation is, there should be a dedicated service kind of account without MFA.
    – SP 2022
    Mar 27, 2020 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.