Tuesday, June 2, 2015

Disable "Request Access" in SharePoint using PowerShell

Hi There,

Using below code, you can disable or hide or remove "Request Access" option from SharePoint. It worked for SharePoint 2010 (could be working for SharePoint 2013).

$contentWebAppServices = (Get-SPFarm).services |
? {$_.typename -eq "Microsoft SharePoint Foundation Web Application"}
# Get All Web Application
foreach($webApp in $contentWebAppServices.WebApplications)
{
Write-Host $webApp.name 
    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 =""
              $SPweb.Update()
           }
        }
    }
}


Hope it will save one's day.
Regards

No comments:

Post a Comment