SharePoint Online: Configure Access Requests Settings using PowerShell

Access Request Settings in SharePoint Online
The access request feature in SharePoint Online allows people to request access to the content they do not have permission to access. It also allows members of the site to send invitations to users who have no permission. Once the invitations are sent, the Site owner should approve them from Site settings >> Access requests and invitations. If you change these settings on the Site Collection level, then new subsites don’t inherit.

How to Set SharePoint Online Access Request Email?

To configure access request email settings in SharePoint Online, Go to:

  1. Site Settings >> Site Permissions >> Access Requests Settings.
  2. This takes you to the SharePoint Online access request page >> Update access request email and hit OK to save your changes.
    sharepoint online access requests settings

Similarly, on group-connected sites, You can set the access requests by going to Settings >> Site Permissions >> Click on “Change how members can share” >> Turn on the “Allow Access requests” and configure who will receive access requests for the site.

sharepoint online powershell set access request email

Please note, SharePoint Online access request email Site Settings must be configured at each site level. Let’s see SharePoint Online PowerShell to set access request email.

If a site is inhering permissions from its parent site, Access request settings also inherited! In other words, you can set access request settings for sites with unique permissions only!

Set SharePoint Online access request settings using PowerShell

Use this PowerShell script to update the SharePoint Online access request 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 for Site URL
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$AccessReqEmail="SharePointSupport@crescent.com"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get the current settings
    $Web = $Ctx.Web
    $Ctx.Load($web.AllProperties)
    $web.RequestAccessEmail
    $Ctx.ExecuteQuery()

    #sharepoint online powershell set access request email
    $Web.RequestAccessEmail =$AccessReqEmail
    #Member settings
    $Web.MembersCanShare = $True
    $web.AssociatedMemberGroup.AllowMembersEditMembership = $True
    $web.AssociatedMemberGroup.Update()

    $Web.Update()
    $Ctx.ExecuteQuery()
}
Catch {
    write-host -f Red "Error configuring Access request settings!" $_.Exception.Message
}

This sets SharePoint Online access request settings with PowerShell.

Disable Access Requests in SharePoint Online using PowerShell:

To disable the access request, simply clear the Email value!

#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 for Site URL
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #sharepoint online disable access request powershell
    $Web = $Ctx.Web
    $Web.RequestAccessEmail = [string]::Empty
    $Web.MembersCanShare = $False    
    $web.AssociatedMemberGroup.AllowMembersEditMembership = $False
    $web.AssociatedMemberGroup.Update()
    $Web.Update()
    $Ctx.ExecuteQuery()
}
Catch {
    write-host -f Red "Error disabling Access request settings!" $_.Exception.Message
}

To change access request Emails of all sites in a site collection or tenant use: SharePoint Online: PowerShell to Change Access Request Email for All Sites

SharePoint Online: Disable Access Request using PnP PowerShell

#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Web
$Web = Get-PnPWeb

#sharepoint online powershell disable access requests
$Web.RequestAccessEmail = [string]::Empty
$Web.SetUseAccessRequestDefaultAndUpdate($False)
$Web.Update()
$Web.Context.ExecuteQuery()

This PowerShell script clears both the Access Request Email and Group Settings! Similarly, to disable access requests for all sites in the tenant, use: SharePoint Online: Disable Access Requests for All Sites using PowerShell

Enable access requests to the owner group of the site using PnP PowerShell:

To set access requests to the site owners, use:

#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Web
$Web = Get-PnPWeb

#Enable Access Request for the site to the Owners Group
$Web.SetUseAccessRequestDefaultAndUpdate($True)
$Web.Update()
$Web.Context.ExecuteQuery()

Similarly, to set Emails in the access request, use the PnP PowerShell cmdlet Set-PnPRequestAccessEmails:

Connect-PnPOnline -Url https://crescent.sharepoint.com/sites/marketing -Interactive

#Update Access Request Email
Set-PnPRequestAccessEmails -Emails @("Admin@crescent.com", "SPAdmin@crescent.com")
sharepoint online powershell set access request email

To change the access request email in SharePoint Online, use the following:

#Enable Access Request for the site to a Email ID
$Web.RequestAccessEmail = "Someone@YourDomain.com"
$Web.SetUseAccessRequestDefaultAndUpdate($False)
$Web.Update()
$Web.Context.ExecuteQuery()

Last but not least: Are access requests and invitations missing in SharePoint Online? Well, that’s because – Access request settings are disabled!

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

19 thoughts on “SharePoint Online: Configure Access Requests Settings using PowerShell

  • If anyone wants to enable ‘Allow access requests’ through Power Automate, you can use a ‘Send an HTTP request to SharePoint’ step – with a POST method. The uri would be: /_api/web/SetUseAccessRequestDefaultAndUpdate(useAccessRequestDefault=@p)?@p=true

    Headers:
    accept – value: application/json;odata=verbose
    content-type – value: application/json;odata=verbose
    X-HTTP-Method – value: MERGE

    body:
    {
    “__metadata”:{“type”:”SP.Web”},
    “RequestAccessEmail”:””
    }

    This will turn on the Access Requests for the site/s and set the default group to the Owners group, so access requests go to everyone in the Owners group.

    Credit to ‘RJB’, in a comment on this blog: https://skodvinhvammen.wordpress.com/2018/08/08/configure-settings-for-access-requests-and-sharing-using-microsoft-flow-and-rest/

    Reply
  • Wow, you have covered almost all the SharePoint cases required in day to day tasks. I am always able to get most of the solutions from your blog. Very helpful posts
    thanks

    Reply
  • Set-SPOSite -Identity https://company.sharepoint.com/sitecollectionURL -DisableSharingForNonOwners

    This is for a single site. No ability to change it on all site collections that I’m aware of.

    Reply
  • Hello,

    Can anyone help me,

    How can I disable the “MembersCanShare” access request attribute in SharePoint Online for all site collections or for specific site collection using PowerShell method?

    Thanks,
    Hemant

    Reply
  • Is there a way to get the inventory for access request settings for all the sites

    Reply
  • For PnP, any thoughts why this line doesn’t work anymore for SharePoint Online:
    $Web.SetUseAccessRequestDefaultAndUpdate($False)

    Getting error message:
    Method invocation failed because [Microsoft.SharePoint.Client.Web] does not contain a method named ‘SetUseAccessRequestDefaultAndUpdate’.

    Reply
  • /_layouts/15/permsetup.aspx can be added to the site url and edit from GUI as well

    Reply
  • Hi,

    We have 1000+ sharepoint online sites and want to set Access request setting to Owners group instead of any email id.

    How to change the Access Request settings to use the Owners group for all these sites?

    Please help.

    Reply
    • Hi Salaudeen,

      Thanks for replying back.

      I have checked the script you have suggested but, it is for adding an email id or changing an email id for receiving all the access requests. What I’m looking for is script which can change Access Request Settings to Site Owners radio button so that members in the site owner group can receive all the site access request.

      Looking forward for your reply.

      Reply
    • Well, The new feature that allows Access Requests to Site Owners is not yet integrated in CSOM!

      Reply
    • Thank you Salaudeen for the info. This is a great post.

      Reply
  • how can I disable the “MembersCanShare” access request attribute in SharePoint Online for all site collections and OneDrive sites? we’ve got thousands of sites and it wouldn’t be feasible to do it one by one.

    Thanks!,
    Steve

    Reply
  • Thanks for the scripts. Great Work!!!
    In my version of SharePoint Online(SPO) the Access Request Settings has a 3rd option to send requests to the Owners group of the site. The owners group of the site is a fixed setting.

    1) Do you know how to change the default owners group? Presently I have a site that is pointing to a group that has been removed from the site.
    2) Can you show me how to change the Access Request settings to use the Owners group?

    Thanks in advance.

    Reply
  • Hi,

    Can we Set SharePoint Online access request settings using PowerShell for all sites?
    Email id will be Service Desk email?

    Could you please help on this requirement.

    Thank You.

    Reply

Leave a Reply

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