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.
Five Challenges in SharePoint Security
...And How to Solve Them. Free White Paper
*Sponsored


Check out these SharePoint products:

1 comment :

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

    ReplyDelete

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...