How to manage ‘Allow access requests’ with PowerShell

26 Apr

In SharePoint access requests to the current web can be managed.
Go to Site Settings; Site Permissions; and select ‘Access Request Settings’ in the ribbon.

Figure 1 – ‘Access Request Settings’ in the ribbon

The screen in figure 2 is then shown allowing you to manage the settings.

Figure 2 – Mange the access requests

My main concern here is to manage the checkbox ‘Allow access requests’ with PowerShell.
Below that checkbox there are two options:

  • The owner group
  • An email address

Disable access requests

To clear the checkbox when an email address is selected set the RequestAccessEmail property of the web to an empty string. This clears the email address in the box and deselects the checkbox.

When the group is selected the procedure is quite different. To deselect the ‘Allow access requests’ checkbox the method SetUseAccessRequestDefaultAndUpdate of the web object has to be used.

You can set both options at a time to disable ‘Allow access requests’ regardless of which setting is used in the web.

$web = Get-PnPWeb
# When an emailaddress is selected, empty it to disable the setting
$web.RequestAccessEmail = ""
# When the first radiobutton, group, is selected, setting it 
# to false disables the setting
$web.SetUseAccessRequestDefaultAndUpdate($false)
$web.Update()
$web.Context.ExecuteQuery()

Figure 3 – Disable access requests

Enable access requests

To enable access requests by group or email address and provide a custom message to users who see the access request page, the following code can be used to set the group:

$web = Get-PnPWeb
# Set the group option to true to enable the setting
$web.SetUseAccessRequestDefaultAndUpdate($true)
# Set a message
$web.SetAccessRequestSiteDescriptionAndUpdate("Welcome to this page (group)")
$web.Update()
$web.Context.ExecuteQuery()

Figure 4 – Enable access requests group

Use the following code to set the email address:

$web = Get-PnPWeb
# Fill the emailaddress and set the group option to false
$web.SetUseAccessRequestDefaultAndUpdate($false)
$web.RequestAccessEmail = "a@b.nl"
# Set a message
$web.SetAccessRequestSiteDescriptionAndUpdate("Welcome to this page (email address)")
$web.Update()
$web.Context.ExecuteQuery()

Figure 6 – Enable access requests email address

Summary

To manage access request settings requires just to check or uncheck one checkbox in the UI. After enabling it the group or email address can be selected and a custom message can be filled in.

When managing this setting using PowerShell you actually manage the group or email address (and the custom message) and thereby indirectly the checkbox.

9 Replies to “How to manage ‘Allow access requests’ with PowerShell

  1. Hi, I’ve been using this method in a powershell script to build sites but it seems that it is no longer supported as the sharing settings have moved in Modern to Settings -> Site Permissions -> Change sharing settings. Do you know if there is a PNP equivalent these days?

  2. Hi Damien and Marc,

    I tested the PowerShell code on a Communication site where the settings for access requests are in both places and it still works.
    Can you provide some additional information so I can possibly help you with this?

    Regards, Anita

  3. This works great, thank you!

    Can you also expand the script to also disabling the other two options:
    “Allow members to share the site and individual files and folders” and “Allow members to invite others to the site members group”?

  4. Is there a way to generate a report where we can find which site has access disabled?
    Sorry I am new to SPO administration.

  5. Hi,

    i have 100s of sharepoint online site and i wanted to know which site having access request enabled, can anyone help me

    Thanks in advance

  6. If we want to apply a default method for the organization for all OneDrive: which PowerShell script enables the default ‘on’ selection of the first radiobutton? (So only the owner gets email approval messages)

  7. Hi

    Nice and easy solution!
    If only…

    Is this only for online version?
    I’m trying to find that useful SetUseAccessRequestDefaultAndUpdate in my on-prem SE version

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.