Consider turning off access requests in SharePoint Online for particular situations. The capability for individuals to request access to your SharePoint Online site can be deactivated either through site settings or via PowerShell. In this blog post, we will guide you on using PowerShell to turn off (or on) user access requests in SharePoint Online.
To disable access requests for a SharePoint Online site, do the following:
- Navigate to the SharePoint Online site where you wish to deactivate access requests.
- Select the Settings gear icon in the upper-right corner and choose “Site Permissions” from the drop-down menu.
- Within the Site Permissions panel, click on the “Change how members can share” link under “Site Sharing.
4. Toggle the “Access Request” settings to the “OFF” position by sliding the button adjacent to it.
5. Click on the “Save” button to commit your changes.
Access requests for your site have been deactivated. Consequently, users without permission will be unable to request access to resources.
SharePoint Online: Disable Access Request using PowerShell
Using PnP PowerShell, let’s disable access requests for a given SharePoint Online site collection. Learn how to install PnP PowerShell here.
#Parameter
$SiteURL = "https://contoso.sharepoint.com/sites/IT"
#Function to disable access request on SharePoint Online Web
Function Disable-PnPAccessRequest
{
[cmdletbinding()]
Param(
[parameter(Mandatory = $true, ValueFromPipeline = $True)] $Web
)
Try {
Write-host -f Yellow "Disabling Access Request on:"$web.Url
If($Web.HasUniqueRoleAssignments)
{
#Disable Access Request
$Web.RequestAccessEmail = [string]::Empty
$Web.SetUseAccessRequestDefaultAndUpdate($False)
$Web.Update()
Invoke-PnPQuery
Write-host -f Green "`tAccess Request has been Disabled!"$web.Url
}
else
{
Write-host -f Yellow "`tWeb inherits permissions from the parent!"$web.Url
}
}
Catch {
write-host "`tError Disabling Access Request: $($_.Exception.Message)" -foregroundcolor Red
}
}
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Call the Function for all webs
Get-PnPSubWeb -IncludeRootWeb -Recurse -Includes HasUniqueRoleAssignments | ForEach-Object { Disable-PnPAccessRequest $_ }
PowerShell to Disable Access Request for All Sites in the Tenant
Let’s show how automating the process of disabling access requests across all SharePoint Online sites in the tenant. This PowerShell script systematically navigates through each site within the tenant and disables access requests if the site employs unique permissions.
#Parameter
$TenantAdminURL = "https://Crescent-Admin.SharePoint.com"
#Function to disable access request on SharePoint Online Web
Function Disable-PnPAccessRequest
{
[cmdletbinding()]
Param(
[parameter(Mandatory = $true, ValueFromPipeline = $True)] $Web
)
Try {
Write-host -f Yellow "Disabling Access Request on:"$web.Url
If($Web.HasUniqueRoleAssignments)
{
#Disable Access Request
$Web.RequestAccessEmail = [string]::Empty
$Web.SetUseAccessRequestDefaultAndUpdate($False)
$Web.Update()
Invoke-PnPQuery
Write-host -f Green "`tAccess Request has been Disabled!"$web.Url
}
else
{
Write-host -f Yellow "`tWeb inherits permissions from the parent!"$web.Url
}
}
Catch {
write-host "`tError Disabling Access Request: $($_.Exception.Message)" -foregroundcolor Red
}
}
#Connect to Admin Center
$Cred = Get-Credential
Connect-PnPOnline -Url $TenantAdminURL -Credentials $Cred
#Get All Site collections - Exclude: Seach Center, Mysite Host, App Catalog, Content Type Hub, eDiscovery and Bot Sites
$SitesCollections = Get-PnPTenantSite | Where -Property Template -NotIn ("SRCHCEN#0", "REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1")
#Loop through each site collection
ForEach($Site in $SitesCollections)
{
#Connect to site collection
Connect-PnPOnline -Url $Site.Url -Credentials $Cred
#Call the Function for all webs
Get-PnPSubWeb -IncludeRootWeb -Recurse -Includes HasUniqueRoleAssignments | ForEach-Object { Disable-PnPAccessRequest $_ }
}
Ensure that you possess access to all sites within your tenant before executing this script. Otherwise, you may encounter “Access denied” or “401 unauthorized” errors.