Change All SharePoint Site’s Access Request Emails with PowerShell

Some time back, I posted an article on Configuring Access Requests from SharePoint. Now, To take the control, Business decided to give the access control requests to the SharePoint help desk, instead of site owners.

So, the requirement is: Update All SharePoint Site’s access request Emails to: SharePoint Help Desk’s Mail id ([email protected]). Let’s change the SharePoint access request email with PowerShell.

PowerShell to Configure Access Request Email for a Site:

$Web = Get-SPWeb "https://intranet.crescent.com/sales" 
If($Web.HasUniquePerm)
{
    $web.RequestAccessEmail ="[email protected]"
    $web.Update()
    Write-host -f Green "`t Access Request Email Configurations Updated for Web:"$Web.URL
}
Else
{
    Write-Host -f Yellow "`t Web Inheriting Access Request Settings from Parent site..."
}

Set Access Request Email for a SharePoint Site Collection using PowerShell:

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Variables for processing
$SiteURL = "https://intranet.crescent.com"

#Get All sites in the given web application
$WebsCollection = Get-SPSite $SiteURL  | Get-SPWeb -Limit All

#Iterate through each web
ForEach ($web in $WebsCollection)
{
    Write-Host "Configuring Access Request Email for:" $web.Url
    
    If (!$web.HasUniquePerm)
    {
        Write-Host -f Yellow "`t Web Inheriting Access Request Settings from Parent site..."
    }
    Else
    {
        $web.RequestAccessEmail ="[email protected]"
        $web.Update()
        Write-host -f Green "`t Access Request Email Configurations Updated for Web:"$Web.URL
    }
}

PowerShell Script to Change All SharePoint Site’s access request Email addresses:

#Get All Web Application
$webApp=Get-SPWebApplication
#Get All site collections
foreach($SPsite in $webApp.Sites)
{
   #get the collection of webs
   foreach($SPweb in $SPsite.AllWebs)
	{
		 #if a site inherits permissions, then the Access request mail setting also will be inherited
		 If(!$SPweb.HasUniquePerm)
		 {
			  Write-Host "Inheriting from Parent site"
		 }
		 elseif($SPweb.RequestAccessEnabled)
		 {
			 $SPweb.RequestAccessEmail ="[email protected]"
			 $SPweb.Update()
		 }
	}
}

BTW, the RequestAccessEnabled is a Read-only property. But if you set the RequestAccessEmail, it will be enabled automatically! so the “elseif($SPweb.RequestAccessEnabled)” may not necessary! just an else will do!!

MOSS 2007 version of PowerShell to set access request Email Settings:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

#For SharePoint 2007 compatibility
function global:Get-SPSite($url){
return new-Object Microsoft.SharePoint.SPSite($url)
}

#Get the web application
Write-Host "Enter the Web Application URL:"
$WebAppURL= Read-Host
$SiteColletion = Get-SPSite($WebAppURL)
$WebApp = $SiteColletion.WebApplication

# Get All site collections
foreach ($SPsite in $webApp.Sites)
{
   # get the collection of webs
   foreach($SPweb in $SPsite.AllWebs)
	{
		  # if a site inherits permissions, then the Access request mail setting also will be inherited
		 if (!$SPweb.HasUniquePerm)
		   {
			  Write-Host "Inheriting from Parent site"
		   }
		 else
	   {
		  #$SPweb.RequestAccessEnabled=$true
		  $SPweb.RequestAccessEmail ="[email protected]"
		  $SPweb.Update()
	   }
	}
}

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

11 thoughts on “Change All SharePoint Site’s Access Request Emails with PowerShell

  • How to change the script so that only specific sites from an input file or comma separated values in the script are changed?
    Thank you.

    Reply
  • how can we do this for sharepoint online?

    Reply
  • How do you have it change a particular subsite rather than all?

    Reply
    • Article updated with the script to configure access request settings for a subsite.

      Reply
  • On running this script Access Request Settings option from the ribbon is disappearing. Is there a way to stop this happening?

    Reply
    • If you don’t see access request settings, You may not have Outgoing E-mail settings configured, Probably!

      Reply
  • Is there a way to turn off site access requests at the site collection level? Thanks for any help.

    Reply
    • Sure, To disable Just Clear the Access request E-mail:
      $SPweb.RequestAccessEmail =””; $SPweb.Update()

      Reply
  • Thanks, this is exactly what I needed!

    Reply
  • This script was straightforward and helpful. Thank you!

    Reply

Leave a Reply

Your email address will not be published.