Friday, June 15, 2012

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 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!!

Here is the 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()
           }
        }
    }



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

6 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

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...