PowerShell Script To Update Access Request Settings Email Address

Objective

This purpose of this document is to mention the steps to access request settings page email address using PowerShell Script. Whenever we try to access an unauthorized site, we are redirected to Access denied page, in that case we can request an access and our request will be sent to a person whose email address is configured in access request settings as email.

Note:

By default, Primary Site Collection Administrators' email addresses are configured in access request settings page whenever a new site collection gets created.

Business Case

 S. No. Business Case
 1 For several reasons customer want to maintain an access matrix to avoid any kind of access violations. So every access request to a SharePoint site must be routed through a group of users who will validate and provide a necessary access to user. For this, we need to configure an email address of compliance team in access request settings, so that access request is routed.

Targeted Audience

  • SharePoint Application Developers
  • SharePoint Administrator
  • SharePoint Architect

Technical Details

Below are the technical details for this PowerShell script,

  1. Execution

    Run:

    • Run the PowerShell Script as “Run as Administrator“.
    • Browse the folder path where you have kept this PowerShell script file and execute a command.

PowerShell Script

  1. ##########################################################################################################################  
  2. ######## V 1.0  
  3. ######## PowerShell Script to update access request settings page email address   
  4. ##########################################################################################################################  
  5.   
  6. if ( (Get-PSSnapin -Name "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null )  
  7. {  
  8.     Add-PsSnapin "Microsoft.SharePoint.PowerShell"  
  9. }  
  10.   
  11. $WebapplicationValue = Read-Host "Enter web application URL"   
  12. Write-Host $WebapplicationValue  
  13.   
  14. $webapp = Get-SPWebApplication $WebapplicationValue  
  15. $newEmail = Read-Host "Enter Email Address:"   
  16. Write-Host $newEmail  
  17.   
  18. foreach($site in $webapp.Sites)  
  19. {  
  20.    Write-Host "Site URL is" $site  
  21.    foreach($web in $site.AllWebs)  
  22.    {  
  23.      $url = $web.url  
  24.      Write-host "Site URl"$url  
  25.      if (!$web.HasUniquePerm)  
  26.      {  
  27.             Write-Host "Access Request Settings is inherted from parent."  
  28.      }  
  29.      else  
  30.      {  
  31.        if($web.RequestAccessEnabled)  
  32.        {  
  33.             Write-Host "Access Request Settings is enabled."  
  34.             Write-Host "Email needs to be updated."  
  35.             $web.RequestAccessEmail = $newEmail  
  36.             $web.Update()  
  37.             Write-Host "Email changed successfully!"  
  38.         }  
  39.       }  
  40.       else  
  41.       {  
  42.             Write-Host "Access Request Settings not enabled."  
  43.       }  
  44.    }  
  45. }  


Similar Articles