kwizcom banner advertisement

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 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 (SharePointSupport@Crescent.com). Lets change SharePoint access request email with PowerShell.

PowerShell to Configure Access Request Email for a Subsite:
$Web = Get-SPWeb "http://intranet.crescent.com/sales" 
If($Web.HasUniquePerm)
{
    $web.RequestAccessEmail ="Support@crescent.com"
    $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 ="SharePointSupport@crescent.com"
        $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 ="SharePointSupport@crescent.com"
                 $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 ="support@crescent.com"
              $SPweb.Update()
           }
        }
    }
Change All SharePoint Site's Access Request Emails with PowerShell Change All SharePoint Site's Access Request Emails with PowerShell Reviewed by Salaudeen Rajack on June 15, 2012 Rating: 5

10 comments:

  1. This script was straightforward and helpful. Thank you!

    ReplyDelete
  2. Thanks, this is exactly what I needed!

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

    ReplyDelete
    Replies
    1. Sure, To disable Just Clear the Access request E-mail:
      $SPweb.RequestAccessEmail =""; $SPweb.Update()

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

    ReplyDelete
    Replies
    1. If you don't see access request settings, You may not have Outgoing E-mail settings configured, Probably!

      Delete
  5. How do you have it change a particular subsite rather than all?

    ReplyDelete
    Replies
    1. Article updated with the script to configure access request settings for a subsite.

      Delete
  6. how can we do this for sharepoint online?

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.