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.
The screen in figure 2 is then shown allowing you to manage the settings.
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()
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()
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 = "email@example.com" # Set a message $web.SetAccessRequestSiteDescriptionAndUpdate("Welcome to this page (email address)") $web.Update() $web.Context.ExecuteQuery()
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.