SharePoint B2B Guest Sharing: Prep, Setup, Invite and Access

Overview


Between May and July 2026, Microsoft switched on SharePoint and OneDrive integration with Microsoft Entra B2B for all commercial tenants, and it can’t be turned off. Every time someone shares with a named external person, Entra creates a guest account for them, and Entra’s own settings decide whether the share is allowed. That makes external sharing depend on settings spread across three admin centres, which is why it can seem obscure.

This post condenses a lab into four stages: prep, setup, invite and access. Each step gives the admin centre path first, then the PowerShell equivalent where scripting helps. Site-level access is done in the admin centre only, where it is easier to control. The scripts look up the tenant, site, library, policies and IDs through Graph, so the only values you type are in the inputs block in Prep. The admin centre steps were tested in the lab. The scripts are built from Microsoft’s documentation; test them in a lab tenant before using them in production.

How B2B Sharing Works


  1. A user shares a folder, or an admin invites an external email address.
  2. Entra checks who is allowed to invite and which domains are allowed, then creates a guest account (User type Guest).
  3. The guest opens the SharePoint link and signs in with their own account: a work or school account, a personal Microsoft account, or a code sent to their email.
  4. Your tenant’s Conditional Access policies run, and the guest gets access to what was shared.

Lab Environment


ItemValue
SiteRoot communication site, https://contoso.sharepoint.com/
Conditional AccessMFA for all users; a location policy that allows sign-ins from the UK only
Cross-tenant MFA trustDisabled
Test guestPersonal Microsoft account

The Short Version


Access neededMethodAdmin needed
A folderThe user shares the folder with Specific people; the share creates the guestNo, but the person sharing must be allowed to invite
The whole siteAdd a security group to the site once; then create each guest in Entra with that group assignedYes

Prep


Roles


TaskMinimum role
Change external collaboration settings in the admin centreExternal Identity Provider Administrator
Assign the Guest Inviter rolePrivileged Role Administrator
Invite guestsGuest Inviter
Create security groupsGroups Administrator
Invite a guest and add them to a group in the same stepUser Administrator
Change SharePoint sharing settingsSharePoint Administrator
Change Conditional Access policiesConditional Access Administrator
Approve access requestsMember of the site’s default Owners group

Modules and Connections


Each scope is listed with the step that needs it. With these granted, the scripts find the tenant, site, library, policies, roles and groups themselves.

Install-Module Microsoft.Graph -Scope CurrentUser
Install-Module Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser

$Scopes = @(
  "Policy.Read.All"                          # read all policies
  "Policy.ReadWrite.Authorization"           # Step 1: guest invite setting
  "RoleManagement.ReadWrite.Directory"       # Step 2: Guest Inviter role
  "Policy.ReadWrite.AuthenticationMethod"    # Step 3: email passcode
  "SharePointTenantSettings.ReadWrite.All"   # Step 4: organisation sharing level
  "Policy.ReadWrite.ConditionalAccess"       # Step 5: Conditional Access
  "Sites.Read.All"                           # find the site and its document library
  "Files.ReadWrite.All"                      # folder-level invite
  "Directory.Read.All"                       # look up users, guests and sign-in details
  "AuditLog.Read.All"                        # sign-in logs
)
Connect-MgGraph -Scopes $Scopes -NoWelcome

Inputs and Discovery


Run this once per session. The inputs are the only values that change from job to job; everything else comes from Graph, and later commands reuse these variables.

# Inputs
$SitePath    = ""                          # blank = root site, or a path such as "sites/Projects"
$FolderPath  = "EXT-Fabrikam"              # folder in the site's default document library
$GuestEmail  = "user@example.com"
$Access      = "Edit"                      # Edit or Read
$PnPClientId = ""                          # optional: your PnP PowerShell app ID (Access Requests)

# Discovered
$Graph    = "https://graph.microsoft.com/v1.0"
$root     = Invoke-MgGraphRequest GET "$Graph/sites/root"
$SpoHost  = ([uri]$root.webUrl).Host                                 # contoso.sharepoint.com
$AdminUrl = "https://$($SpoHost.Split('.')[0])-admin.sharepoint.com"
$Site     = if ($SitePath) { Invoke-MgGraphRequest GET "$Graph/sites/${SpoHost}:/$SitePath" } else { $root }
$SiteUrl  = if ($SitePath) { $Site.webUrl } else { $Site.webUrl.TrimEnd('/') + '/' }
$Drive    = Invoke-MgGraphRequest GET "$Graph/sites/$($Site.id)/drive"

[pscustomobject]@{ Site = $SiteUrl; Admin = $AdminUrl; Library = $Drive.name; Tenant = (Get-MgContext).TenantId }

# Warn if any input still holds an example value
if ($GuestEmail -match "example\.com") { Write-Warning "GuestEmail still holds the example value: $GuestEmail" }

# SharePoint Online PowerShell runs through Windows PowerShell compatibility in PowerShell 7
Import-Module Microsoft.Online.SharePoint.PowerShell -UseWindowsPowerShell
Connect-SPOService -Url $AdminUrl

Check the Current State


Record these values before changing anything.

[pscustomobject]@{
  AllowInvitesFrom = (Invoke-MgGraphRequest GET "$Graph/policies/authorizationPolicy").allowInvitesFrom
  TenantSharing    = (Get-MgAdminSharepointSetting).SharingCapability
  SiteSharing      = (Get-SPOSite -Identity $SiteUrl).SharingCapability      # the root site defaults to Anyone
  GuestEmailOtp    = (Invoke-MgGraphRequest GET "$Graph/policies/authenticationMethodsPolicy/authenticationMethodConfigurations/email").allowExternalIdToUseEmailOtp
  InboundB2B       = (Invoke-MgGraphRequest GET "$Graph/policies/crossTenantAccessPolicy/default").b2bCollaborationInbound.usersAndGroups.accessType
}

# Conditional Access policies: which use a location, what they grant, and whether guests are excluded
(Invoke-MgGraphRequest GET "$Graph/identity/conditionalAccess/policies").value | ForEach-Object {
  [pscustomobject]@{
    Policy         = $_.displayName
    State          = $_.state -replace "enabledForReportingButNotEnforced", "reportOnly"
    Location       = [bool]$_.conditions.locations
    Grant          = $_.grantControls.builtInControls -join ","
    GuestsExcluded = [bool]$_.conditions.users.excludeGuestsOrExternalUsers
  }
} | Format-Table -Wrap

Setup


Every one of these settings has to allow the guest; whichever is most restrictive wins.

Step 1: Guest Invite Settings


When a user shares with a new external address, Entra checks whether that user is allowed to invite guests. If they aren’t, the share fails with “Guest invitations not allowed for your company”.

Entra admin center > Entra ID > External Identities > External collaboration settings

Guest invite optionWho can inviteallowInvitesFrom
Member users and users assigned to specific admin roles can invite guest users including guests with member permissionsEvery memberadminsGuestInvitersAndAllMembers
Only users assigned to specific admin roles can invite guest users (used in the lab)User Administrator and Guest InviteradminsAndGuestInviters
  • Collaboration restrictions: Allow invitations to be sent to any domain
  • Save

Microsoft recommends the second option, where only admins and people with the Guest Inviter role can invite.

$InvitePolicy = "adminsAndGuestInviters"   # or "adminsGuestInvitersAndAllMembers"

if ((Invoke-MgGraphRequest GET "$Graph/policies/authorizationPolicy").allowInvitesFrom -ne $InvitePolicy) {
  Invoke-MgGraphRequest PATCH "$Graph/policies/authorizationPolicy" -Body @{ allowInvitesFrom = $InvitePolicy }
}
"allowInvitesFrom: $((Invoke-MgGraphRequest GET "$Graph/policies/authorizationPolicy").allowInvitesFrom)"

Step 2: Assign Guest Inviter


Skip this step if you chose the member option in Step 1. Users with Guest Inviter can invite even when only admin roles are allowed to. They don’t need the SharePoint Administrator role to share.

Guest Inviter goes to specific, named users, never in bulk.

Entra admin center > Entra ID > Roles & admins > Guest Inviter > Add assignments > select the users who will share > Add

The script only reports. It lists who holds Guest Inviter, with names and UPNs pulled from the role assignments, or says that no one does. It lists active assignments; users who are only eligible through Privileged Identity Management don’t appear.

$role    = Get-MgRoleManagementDirectoryRoleDefinition -Filter "displayName eq 'Guest Inviter'"
$holders = (Invoke-MgGraphRequest GET "$Graph/roleManagement/directory/roleAssignments?`$filter=roleDefinitionId eq '$($role.Id)'&`$expand=principal").value

if (-not $holders) {
  "No one holds Guest Inviter. allowInvitesFrom: $((Invoke-MgGraphRequest GET "$Graph/policies/authorizationPolicy").allowInvitesFrom)"
} else {
  $holders | ForEach-Object {
    [pscustomobject]@{
      Name = $_.principal.displayName
      UPN  = $_.principal.userPrincipalName
      Type = $_.principal.'@odata.type' -replace "#microsoft.graph.", ""
    }
  } | Format-Table -Wrap
}

To assign it to one named user from PowerShell instead of the admin centre:

$u = Get-MgUser -UserId "named.user@yourdomain.com"
New-MgRoleManagementDirectoryRoleAssignment -DirectoryScopeId "/" -PrincipalId $u.Id -RoleDefinitionId $role.Id

Step 3: Guest Sign-In Defaults


Both of these are on by default. Check they haven’t been changed.

SettingAdmin centre pathRequired value
Email one-time passcodeEntra ID > External Identities > All identity providers > Built-in > Email one-time passcodeYes, so guests without a Microsoft or work account can sign in with an emailed code
Inbound B2B collaborationEntra ID > External Identities > Cross-tenant access settings > Default settings > Edit inbound defaults > B2B collaborationAllow access for all external users and all applications

Turn the email passcode back on only if it’s off:

$otpUri = "$Graph/policies/authenticationMethodsPolicy/authenticationMethodConfigurations/email"

if ((Invoke-MgGraphRequest GET $otpUri).allowExternalIdToUseEmailOtp -eq "disabled") {
  Invoke-MgGraphRequest PATCH $otpUri -Body @{
    "@odata.type"                = "#microsoft.graph.emailAuthenticationMethodConfiguration"
    allowExternalIdToUseEmailOtp = "enabled"
  }
}

Step 4: SharePoint Sharing Level


Use New and existing guests. Guests then have to sign in, so Conditional Access applies to them. With Anyone links, people open content without signing in, so no Entra policy applies.

Organisation: SharePoint admin center > Policies > Sharing

  • SharePoint: New and existing guests
  • File and folder links: Specific people
  • Save

Site: SharePoint admin center > Sites > Active sites > select the site > Settings > More sharing settings

  • External sharing: New and existing guests
  • Default sharing link type: clear Same as organization-level setting, then select Specific people
  • Save

Members sharing: Site > Settings > Site permissions > Sharing settings > Change how members can share > allow members to share files and folders > Save

The script raises the organisation level only if it’s too low to invite new guests, so other sites that rely on Anyone links aren’t affected. The site itself is set to New and existing guests.

# Organisation level (Microsoft Graph)
if ((Get-MgAdminSharepointSetting).SharingCapability -in "disabled","existingExternalUserSharingOnly") {
  Update-MgAdminSharepointSetting -SharingCapability "externalUserSharingOnly"
}

# Default link type and site level (SharePoint Online PowerShell)
Set-SPOTenant -DefaultSharingLinkType Direct
Set-SPOSite -Identity $SiteUrl -SharingCapability ExternalUserSharingOnly -DefaultSharingLinkType Direct

Step 5: Conditional Access


This was what blocked guests in the lab. In a Conditional Access policy, All users includes guests, so the UK-only policy also blocked any guest signing in from outside the UK. The fix is to exclude B2B guests from the location policy and keep requiring MFA for them.

Find the policies (report only)

The script never changes a policy. It lists every enabled or report-only policy that blocks by location and shows whether it still applies to B2B guests. It also lists the MFA policies and whether guests are excluded from them or face an authentication strength requirement.

$caUri    = "$Graph/identity/conditionalAccess/policies"
$policies = (Invoke-MgGraphRequest GET $caUri).value

# Location block policies: do they still apply to B2B guests?
$policies | Where-Object {
  $_.state -ne "disabled" -and $_.conditions.locations -and $_.grantControls.builtInControls -contains "block"
} | ForEach-Object {
  $u       = $_.conditions.users
  $applies = ($u.includeUsers -contains "All" -or $u.includeGuestsOrExternalUsers) -and
             ($u.excludeGuestsOrExternalUsers.guestOrExternalUserTypes -notmatch "b2bCollaborationGuest")
  [pscustomobject]@{
    Policy          = $_.displayName
    State           = $_.state -replace "enabledForReportingButNotEnforced", "reportOnly"
    AppliesToGuests = $applies
    Action          = if ($applies) { "Exclude B2B guests" } else { "None" }
  }
} | Format-Table -Wrap

# MFA policies: guests should stay included, with no authentication strength they can't meet
$policies | Where-Object {
  $_.grantControls.builtInControls -contains "mfa" -or $_.grantControls.authenticationStrength
} | ForEach-Object {
  [pscustomobject]@{
    Policy         = $_.displayName
    State          = $_.state -replace "enabledForReportingButNotEnforced", "reportOnly"
    GuestsExcluded = [bool]$_.conditions.users.excludeGuestsOrExternalUsers
    Strength       = $_.grantControls.authenticationStrength.displayName
  }
} | Format-Table -Wrap

Change: admin centre

Entra admin center > Entra ID > Conditional Access > Policies > open the policy the report flagged > Users > Exclude

  • Tick Guest or external users
  • Tick B2B collaboration guest users and B2B collaboration member users
  • External Microsoft Entra organizations: All
  • Save

Change: terminal

This is a separate procedure for one named policy taken from the report. It reads that policy’s whole users section, adds the guest types to any existing exclusion and writes it back, so the other include and exclude lists are kept.

$PolicyName = ""   # copy the policy name from the report

$p = (Invoke-MgGraphRequest GET $caUri).value | Where-Object { $_.displayName -eq $PolicyName }
if (-not $p) { throw "Policy not found: '$PolicyName'" }

$users    = $p.conditions.users
$existing = "$($users.excludeGuestsOrExternalUsers.guestOrExternalUserTypes)" -split "," | Where-Object { $_ }
$users.excludeGuestsOrExternalUsers = @{
  guestOrExternalUserTypes = (@($existing) + "b2bCollaborationGuest", "b2bCollaborationMember" | Select-Object -Unique) -join ","
  externalTenants          = @{
    "@odata.type"  = "#microsoft.graph.conditionalAccessAllExternalTenants"
    membershipKind = "all"
  }
}

Invoke-MgGraphRequest PATCH "$caUri/$($p.id)" -Body @{ conditions = @{ users = $users } }
"Guest exclusion now on '$PolicyName': $((Invoke-MgGraphRequest GET "$caUri/$($p.id)").conditions.users.excludeGuestsOrExternalUsers.guestOrExternalUserTypes)"

Leave guests included in the MFA policy (All users, Require multifactor authentication). Don’t require phishing-resistant MFA or a compliant device for guests. They can’t meet those requirements in your tenant while MFA trust is disabled.

Allow 15 to 60 minutes for invite settings and role assignments to take effect before you test.

Invite


Folder-Level Invite


This is the best default for a new external user: one step, no admin involved, and access to that folder only.

  1. Site > Documents > select the folder > Share
  2. Check the link setting shows Specific people
  3. Enter the external email address > Can edit or Can view > Send

Entra creates the guest, SharePoint sends the sharing email and the folder is shared, all in one action. Give each external company its own folder (for example EXT-Fabrikam); guests who share a folder can see each other’s names in Manage access.

Graph equivalent: the account signed in to Graph does the sharing, so it must be allowed to invite. Microsoft doesn’t allow new guests to be invited with app-only access. The folder is found by its path in the library discovered during prep.

$path = ($FolderPath -split "/" | ForEach-Object { [uri]::EscapeDataString($_) }) -join "/"
$item = Invoke-MgGraphRequest GET "$Graph/drives/$($Drive.id)/root:/$path"

Invoke-MgInviteDriveItem -DriveId $Drive.id -DriveItemId $item.id -BodyParameter @{
  recipients     = @(@{ email = $GuestEmail })
  roles          = @($(if ($Access -eq "Read") { "read" } else { "write" }))
  requireSignIn  = $true
  sendInvitation = $true
  message        = "Shared folder: $FolderPath"
}

Site-Level Invite


Microsoft’s documentation says site owners can share a site with new guests, but in this lab Share site wouldn’t add an external user who wasn’t already in the directory. The method below creates the guest in Entra with site access already in place. The site’s access comes from a security group, and each guest is added to that group as they’re created, before they open the invitation. It’s done in the admin centre, where each step is visible and easy to control.

One-time setup: create the group and add it to the site

  1. Entra admin center > Entra ID > Groups > All groups > New group
    • Group type: Security
    • Group name: for example SG-EXT-<site>-Members for edit access; create a second group, SG-EXT-<site>-Visitors, if you also need read-only access
    • Membership type: Assigned
    • Create
  2. Site > Settings > Site permissions > Share site
    • Enter the group name
    • Permission: Edit for the Members group, Read for the Visitors group
    • Clear Send email
    • Add

For each guest: Entra admin center > Entra ID > Users > New user > Invite external user

TabSetting
BasicsEmail, Display name, tick Send invite message, and put the site URL in the message
PropertiesLeave Usage location blank; it’s only needed to assign a licence
Assignments+ Add group > SG-EXT-<site>-Members or SG-EXT-<site>-Visitors > Select
Review + inviteInvite

The guest has site access through the group from the moment they’re created. The invite email’s Accept invitation button opens My Apps, not your site, and the portal has no setting to change that, so the site URL in your message is what the guest should open. To remove a guest’s site access, remove them from the group.

Access


Guest First Sign-In


  1. Open the SharePoint link from the sharing email, or the site or folder URL, in a private browser window. The address must start with https://contoso.sharepoint.com/.
  2. Sign in with a work or school account or a Microsoft account, or select Send code for an emailed passcode.
  3. Review permissions > Accept.
  4. At More information required, register Microsoft Authenticator with this tenant.
  5. The shared folder or site opens.

With MFA trust disabled, every guest registers MFA in your tenant. Guests with a work account also complete their own organisation’s MFA first. Personal Microsoft account and emailed-code guests always do MFA in your tenant.

Access Requests


An access request is how someone asks a site owner for access they don’t have. This part wasn’t tested in the lab; the steps follow Microsoft’s documentation.

How a request startsWhat happens
A signed-in user opens a site, folder or file they don’t have permission toThe access denied page offers a way to request access, as long as access requests are turned on
Someone who isn’t a site owner uses Share siteThe share becomes a request for a site owner to approve

Only people who can sign in to your tenant can request access: members and existing guests. A new external person has no account in your directory yet, so they can’t sign in to ask. Invite them with one of the methods in Invite instead. A typical guest request comes from someone with a folder share who follows a link to the site home page.

Turn on access requests: Site > Settings > Site permissions > Sharing settings > Change how members can share

SettingOptions
Sharing permissionsSite owners and members can share files, folders and the site; or site owners and members can share files and folders, but only site owners can share the site; or only site owners can share files, folders and the site
Allow access requestsOn
Send requests toThe site’s owners (default for communication sites), or Specific email for a user or distribution list
MessageOptional text shown on the request page

Select Save.

Approve or decline

  1. The approver receives an email for each new request.
  2. Site > Settings > Site contents > Access requests. The button only appears while requests are pending.
  3. Under Pending Requests, select … on the request.
  4. Choose the permission level, and add a message if you want to record the decision.
  5. Select Approve or Decline. Show History lists past requests.

Only site admins, SharePoint Administrators and members of the site’s default Owners group can use the Access requests page. Full Control given to someone outside the Owners group isn’t enough. The same page lists guest invitations sent from the site; select … > Withdraw to cancel one that hasn’t been accepted yet.

Approving and declining is done in the browser. Microsoft Graph and SharePoint Online Management Shell have no documented command for the request settings, which are stored on the site as RequestAccessEmail. The open-source PnP PowerShell module can read and change them:

Connect-PnPOnline -Url $SiteUrl -Interactive -ClientId $PnPClientId

Get-PnPRequestAccessEmails                                  # current recipients
Set-PnPRequestAccessEmails -Disabled:$false                 # on, requests go to the site owners
Set-PnPRequestAccessEmails -Emails "approver@contoso.com"   # on, requests go to one address
Set-PnPRequestAccessEmails -Disabled                        # off

Verify


CheckAdmin centreWhat to look for
Guest createdEntra ID > Users > the guestUser type Guest, B2B collaboration Accepted
Conditional AccessEntra ID > Monitoring & health > Sign-in logs > the guest’s sign-in > Conditional Access tabLocation policy Not applied, MFA policy Success
Folder accessFolder > Details > Manage accessGuest listed
Site accessEntra ID > Groups > SG-EXT-<site>-Members or -Visitors > MembersGuest listed
# The guest and their invitation state
$guest = Get-MgUser -Filter "mail eq '$GuestEmail'" -Property id,displayName,mail,userType,externalUserState
$guest | Select-Object DisplayName, Mail, UserType, ExternalUserState

# The guest's recent sign-ins and Conditional Access result
Get-MgAuditLogSignIn -Filter "userId eq '$($guest.Id)'" -Top 5 |
  Select-Object CreatedDateTime, AppDisplayName, ConditionalAccessStatus,
    @{n='Country';e={$_.Location.CountryOrRegion}}, @{n='Error';e={$_.Status.ErrorCode}}

# The guest's group memberships (site access comes from the SG-EXT group)
Get-MgUserMemberOf -UserId $guest.Id | ForEach-Object { $_.AdditionalProperties.displayName }

What the Lab Showed


Sign-in from outside the UKResultWhy
Tenant Global Administrator (a member)BlockedThe location policy still applies to members
Personal Microsoft account guestAllowed, MFA requiredCounts as a B2B collaboration guest user, so the exclusion applies
Users with Guest Inviter sharing with new addressesGuest created automaticallyGuest Inviter can invite even when only admin roles are allowed to

Conditional Access works out location from the sign-in’s public IP address. Profile fields such as Usage location or Country have no effect on it.

Troubleshooting


SymptomCauseFix
“Guest invitations not allowed for your company”The person sharing isn’t allowed to inviteStep 1 or Step 2, then wait up to 60 minutes
“Selected user account does not exist in tenant ‘Microsoft Services’” (app 2793995e-...)The guest followed a link with no tenant in it, which opened My Apps; a personal Microsoft account then signed in to Microsoft’s own tenantOpen the SharePoint URL instead; put the site URL in the invite message
Guest blocked outside the UKThe location policy targets All users, which includes guestsStep 5
Share site won’t add a new external userThe guest isn’t in the directory yetSite-Level Invite: invite in Entra with the site’s security group assigned
Guest can’t register MFAA policy restricts MFA registration by location, or no method is enabled for all usersExclude guests from that policy; enable Authenticator for all users
No way to request access on the access denied pageAccess requests are off for the siteAccess Requests: turn on Allow access requests
Approver gets “Access Denied” on Access requests, or “Request approval failed”The approver isn’t a site admin or in the site’s default Owners groupAdd them to the Owners group
Site owners don’t receive request emailsThe site uses mail-enabled security groupsSend requests to a Specific email address instead

References