Add multiple users in a SharePoint site

A few days ago, I had a request to add multiple users in a SharePoint site but using the default interface, I can only add one by one. If we have a long list of users that need to be added to the site this tasks can take a while. So I come up with a PowerShell that will do this task based on a CSV file that contains the email that will make this process faster

For this PowerShell, I will use the PnP PowerShell but you can achieve the same using Microsoft 365 CLI.

Note: For the authentication piece, I will use the PnPManagementShell rather than the UseWebLogin traditional method. You can read more about it on the following link:

If you want to know the level of permission needs to accept the PnP Application on your tenant, check the following link:

$siteUrl = "https://contoso.sharepoint.com/sites/SiteToConnect"
Connect-PnPOnline -Url $siteUrl -PnPManagementShell -LaunchBrowser

Write-Host "Adding External Users"
$UsersToImport = Import-Csv -Path ".\Users.csv"
$MembersGroup = Get-PnPGroup -AssociatedMemberGroup

foreach ($user in $UsersToImport) {
    Write-Host "Adding User Email" $user.email
    Add-PnPUserToGroup -EmailAddress $user.email -Identity $MembersGroup #-SendEmail
}

You can adjust the PnP group that you want to add the users on (SharePoint groups). If you don’t know the user that needs to be added to the site it’s also easy for everyone to send you this CSV file or similar so you can apply to the SharePoint site. You can also include the role that you want on this CSV file and therefore add the users to the desired places.

2 Comments

  1. Raphael said:

    It works to add many users to a SharePoint list?

    June 11, 2021
    Reply
    • David Ramalho said:

      Hi,

      This will allow the users to access your SharePoint list if the permissions are the default ones. If the permissions are broken on the list you may need to adjust the code for that case.

      My best,
      David Ramalho

      October 21, 2021
      Reply

Leave a Reply

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