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.
It works to add many users to a SharePoint list?
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
What if you want to add a user to multiple sites with a CSV file, with PNP How can you add the commands, the Connect-PNP -URL $URL -Interactive and then Set-PNPWebPermissions on the next line? I have a CSV File with 8000 users, multiple sites, and different roles. My CSV File is : URL, User, Role. I can not get the ForEach in a loop to format / syntax correct.