Tuesday, June 2, 2015

Set "Request Access" Email Address using PowerShell in SharePoint 2010

Using below code, you can set "Request Access" Email ID in SharePoint. It worked for SharePoint 2010 (could be working for SharePoint 2013).

$path = "C:\Logs.txt"

$contentWebAppServices = (Get-SPFarm).services |
? {$_.typename -eq "Microsoft SharePoint Foundation Web Application"}
# Get All Web Application
foreach($webApp in $contentWebAppServices.WebApplications)
{
add-content -Path $path -Value $webApp.name -Force
if($webApp.name -ne "")
{
    foreach ($SPsite in $webApp.Sites)
    {
    add-content -Path $path -Value $SPsite.URL -Force
       # get the collection of webs
       foreach($SPweb in $SPsite.AllWebs)
        {
    add-content -Path $path -Value    $SPweb.URL -Force
              # if a site inherits permissions, then the Access request mail setting also will be inherited



        try
            {
                if (!$SPweb.HasUniquePerm)
                  {
                  add-content -Path $path -Value "Inheriting from Parent site" -Force
                 }
                 elseif($SPweb.RequestAccessEnabled)
                {
           
                  $SPweb.RequestAccessEmail =""
                  $SPweb.Update()
                  add-content -Path $path -Value "Turned off for : " $SPweb.Name -Force
                }

            }
        catch [system.exception]
            {
            add-content -Path $path -Value $Error[0].Exception.Message -Force
            }







        }
    }
  }
}


Disable "Request Access" Email Address using PowerShell in SharePoint 2010

1 comment: