SharePoint Online: Share Site and Invite External Users using PowerShell
Requirement: Share SharePoint Online Site with Multiple External Users using PowerShell.
How to Grant Access to External Users in SharePoint Online?
Do you need to share a SharePoint site with external users? Well, This guide will show you how to add an external user to your SharePoint Online site. We will also show you how to use PowerShell to add external users to your SharePoint Online. This can be especially useful if you manage multiple SharePoint Online sites and need to grant access quickly and easily. We will walk you through the required steps and provide examples to help make the process easier!
Before adding an external user to the SharePoint Online site, ensure your SharePoint Online tenant is configured to allow external users – which is turned off by default! You can quickly check if external access is enabled for your SharePoint tenant by going to the:
- Go to the SharePoint Admin Center under Microsoft 365 admin center, Expand Policies, and then “Sharing”.
- In the “External Sharing”, make sure the “SharePoint” settings are not set to “Only people in your organization” (which means it’s accessible only to internal users). If it’s set to “Existing Guests”, you must invite an external user to your Azure AD before adding them to SharePoint Online. If you want to allow anonymous users, set it to “Anyone”.
The default for communication sites and classic sites is “Only people in your organization.” even though you set sharing at the organization level, and The default sharing setting for Microsoft 365 group-connected team sites is “New and existing guests.”
How to share a SharePoint site with external users?
Once you have confirmed the external sharing settings at the organizational level (Tenant level), the next step is to check if the external sharing is enabled at the individual site level by:
- Login to SharePoint Admin Center, Expand Sites >> Active Sites.
- Select the target site from the list and click on the “Sharing” button in the ribbon.
- In the Sharing panel, make sure the sharing level is not set to “Only People in your Organization” (which means, External sharing is disabled!).
That’s all! Now, we are ready to invite external collaborators to our SharePoint site. For more on allowing external sharing in SharePoint Online and OneDrive, see How to Enable External Sharing in SharePoint Online.
How to Share a SharePoint Online Site with External Users?
Once you confirm SharePoint Online external sharing is enabled for your site, do the following to share a SharePoint site with external users:
- Navigate to your SharePoint Online site that you want to share with external users.
- Click on the “Share” button in the top-right corner. Alternatively, you can click on Site Settings >> Site Permissions >> Share Site.
- In the Share site panel, Enter the E-mail ID of the external user, select the permission level such as Read, Edit, etc., to allow them to download/upload, and choose whether a sharing invitation is to be sent. Then click on Share to add an external user to SharePoint Online. You can also add them as group members.
External user invitations from SharePoint Online will be sent to the recipients, and they can access the site from the link in the email. Let’s see how to share with external users using PowerShell in SharePoint Online:
SharePoint Online: Share with External Users using PowerShell
This PowerShell script invites external users to a SharePoint site and grants View permissions to the site. A custom email message is also included in the invitation email.
#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"
#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$Users = "Mark.Ellis@gmail.com","Sayeed.Alhajiri@gmail.com"
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Create Request List
$UserList = New-Object "System.Collections.Generic.List``1[Microsoft.SharePoint.Client.Sharing.UserRoleAssignment]"
#Set Role for each user
ForEach($User in $Users)
{
$UserRoleAssignment = New-Object Microsoft.SharePoint.Client.Sharing.UserRoleAssignment
$UserRoleAssignment.UserId = $User
$UserRoleAssignment.Role = [Microsoft.SharePoint.Client.Sharing.Role]::View #Other Options: Edit, or Owner
$UserList.Add($UserRoleAssignment)
}
#Send invites
$EmailMessage = "Please accept this invitation to our Marketing Site. Thanks!"
[Microsoft.SharePoint.Client.Sharing.WebSharingManager]::UpdateWebSharingInformation($Ctx, $Ctx.Web, $UserList, $True, $EmailMessage, $True, $True)
$Ctx.ExecuteQuery()
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
This script sends invites to external users as:
External Users can click the link in the email to access your SharePoint site. Once the user accepts the invitation, they can access all of the site’s content and collaborate with other members. Please note that the user must have a Microsoft Live ID! They can create a Microsoft account from their Email if it’s not created already (They don’t need any Microsoft License, BTW!). By following the steps outlined in this article, administrators and site owners can easily add guest users to their SharePoint Online sites, giving them access to the content and resources they need.
Conclusion
In conclusion, sharing a SharePoint Online site with external users can be a crucial step in collaborating with partners and clients. By using the PowerShell script provided in this article, organizations can automate the process of sharing their SharePoint Online site and inviting external users. This can save time and effort, improving collaboration and communication!
You can also invite an external user using SharePoint Online Management Shell cmdlet or PnP PowerShell! How to Add an External User to SharePoint Online using PowerShell?
To add an external user to Azure Active Directory, login to Microsoft Admin Center at https://admin.microsoft.com/ >> Open “Azure Active Directory” Admin Center >> Click on “Users” >> New Guest user. Enter the Name of your guest user, fill in the Email and optionally other fields, and click on the “Invite” button at the bottom of the page to invite multiple external users. You can also use the PowerShell cmdlet New-AzureADMSInvitation to invite guests to Azure AD.
More info: How to Invite a Guest User to Azure AD for SharePoint Online?
To check the external sharing settings of a site collection, Login to SharePoint Online Admin Center >> Click on the “Sites” link from the left navigation >> Select the site collection from the site’s list, and click on the “Sharing” button in the toolbar. The sharing page displays the external sharing settings of the current site.
More info: How to check external sharing in SharePoint Online?
To allow external sharing in SharePoint online using PowerShell, use Set-SPOTenant and Set-SPOSite cmdlets with the “SharingCapability ExternalUserAndGuestSharing” parameter. You can also use the PnP PowerShell cmdlets Set-PnPTenant and Set-PnPTenantSite.
More info: How to Enable External Sharing in SharePoint Online using PowerShell?
To share a SharePoint folder with external users, navigate to the document library where the folder is located and select the folder to share. Then right-click on the folder and select “Share”. Choose the link settings as “Specific people” and click on “Apply”. Enter the external user’s email address and select the appropriate permission level for the user. Once we have entered the user’s information, click on the Send button to send the invitation to the user. It’s important to note that external sharing should be enabled first to share a folder with external users in SharePoint. Moreover, the guest user must have a Microsoft account (Personal/Work/School account) to access the shared file or folder, and they’ll have to enter the verification code sent to their Email.
There is no longer a Share button on the Site page to follow these instructions. There is a Membership button, but if you Add Members it tells you cant add external users here and to use the Webmail link. There must be a less clunky way to do this simple job.
Chances are: You are not having Edit access; Site is set to restrict Members from sharing site; You are using Adblocker!
Is there a way to add new external users direclty to a SharePoint group without sharing individual files, folders or the whole site?
Yes! You can add an external user to SharePoint group – As you add internal users! More here: How to Add External User to SharePoint Group?
I have a document library that contains many folders (each folder will be shared to a different external user). Is there any way I can use PowerShell to share pre existing folders to external users via CSV?
Thanks
Sure! You can set folder permissions from a CSV: How to Share SharePoint Folders from a CSV file using PowerShell?
I’ve tried this multiple times and I receive no errors and no emails.
Is there somewhere to check if invitations have been sent?
Yes, Go to Site Settings >> ” Access requests and invitations ” to get all pending access requests and invitations.