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.

Be First to Comment

Leave a Reply

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