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 "http://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 = "http://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!

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

Leave a Reply