Managing SharePoint 2010 Access Request Settings Via PowerShell

SharePoint has a built-in mechanism to manage access requests. Users can request access to sites and documents when they are denied access, or they can request additional privileges to update content if they only have read access.

The requests go to one or more email addresses which are defined at the site level. The definitions follow inheritance, meaning that if a child site inherits its parent’s permissions, the child site will inherit the access request settings as well. The property to check if a site is inheriting permissions is named HasUniqueRoleDefinitions.

There are two properties which control the access request configuration, first is RequestAccessEnabled, a Boolean flag which turns on or off the access request feature for the site. The second property defines one or more email addresses where requests will be sent to. It is named RequestAccessEmail. To specify multiple email addresses, separate each with a semicolon. The image below illustrates the GUI for modifying these two properties. It is accessed on the site permissions page, on the far right of the ribbon.

Today I will share some sample code which walks through every site collection and site within a given web application, and writes to the screen the relevant access request settings.

Add-PSSnapin Microsoft.SharePoint.Powershell
$webapp = Get-SPWebApplication "Portal Home"
foreach($spsite in $webapp.Sites)
{
   foreach($web in $spsite.AllWebs)
   {
      Write-Host "On Web" $web.Title ", URL" $web.URL
      if (!$web.HasUniqueRoleDefinitions) {
         Write-Host "`tAccess request settings inherited from parent."
      }
      if ($web.RequestAccessEnabled) {
         Write-Host "`tAccess requests go to :" $web.RequestAccessEmail
      }
      else {
         Write-Host "`tAccess requests are disabled."
      }
   }
}

2 thoughts on “Managing SharePoint 2010 Access Request Settings Via PowerShell”

  1. Can I achieve the same thing – list of Site URL and Manage Access Request field value through Dot Net code and have the list displayed in a sharepoint site page / SSRS..any form of report.

    1. Hi Triparna,

      Thanks for stopping by the site. Yes, the same info can be pulled by the .NET SharePoint API, that’s the cool thing about Powershell; it uses the same API as the .NET languages like C#.

      To get the information onto a SharePoint page, you could build a custom web part to gather the information (via the SharePoint API) and output it as HTML. This would display real time, live information every time the page is refreshed. A potential issue with this approach arises if you want the page/report to be viewed by normal users, in which case you can use RunWithElevatedPrivileges, but then again exposing all this information across all sites to an unprivileged user doesn’t seem like a good idea. If this page is only accessed by SharePoint administrators you wouldn’t need to worry about that.

      To view this info in an SSRS report you need to have the data available as a data source. In this case, the data needs to be pulled from the API and aggregated, so you would need something in between, like a custom web service, to query and pull the data together, and then present it to SSRS.

      Another option would be to have a PowerShell script such as this run as a scheduled task on a SharePoint server, and modify it so that the output is saved as a csv file, (rather than outputting to the screen as I have done) and have the script also upload the csv file to a SharePoint document library. You could then use the document library to open the CSV “reports” in Excel.

      Hope this helps

      -Lance

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.