Wednesday, April 22, 2015

SharePoint 2013: change all site access request emails

Introduction

This posting shows you how to change all of the site access request emails in one go using PowerShell.  To see how to disable such access requests in bulk, check out the Notes section.

Procedures
  1. To quickly review the RequestAccessEmail settings for all subwebs of a site collection, execute the following in an elevated SharePoint Management shell:
    Get-SPSite [your Site Collection URL] | Get-SPWeb -limit all | Sort-Object Title | ft title, HasUniquePerm, RequestAccessEnabled, RequestAccessEmail | Format-table -auto
  2. To set the RequestAccessEmail setting for all subwebs of a site collection, execute the following script in an elevated PowerShell window:
    if ((Get-PSSnapin -Name "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PsSnapin Microsoft.SharePoint.PowerShell } $siteURL = Read-Host "Enter the URL to the site collection" $email = Read-Host "Enter the new Request Access email address" $site = Get-SPSite $siteURL $countupdated = 0 $countnotupdated = 0 ForEach ($web in $site.AllWebs) { If (!$web.HasUniquePerm) { Write-Host $web.Title, " - Inherits from parent, no change made" $countnotupdated = $countnotupdated + 1 } Else { $web.RequestAccessEmail = $email $web.Update() Write-Host $web.title, " - updated email" $countupdated = $countupdated + 1 } } Write-Host "RequestAccessEmail Updating Completed" Write-Host "Total updated: "$countupdated Write-Host "Total not updated: "$countnotupdated
References
  • Web: this is a subsite.  Use Get-SPWeb to retrieve.
  • Site: this is generally used to refer to a site collection.  Use Get-SPSite to retrieve.
Notes
  • I found that if you check the value of RequestAccessEmail via PowerShell and compare that with the value you see if you actually navigate to the site's settings for this  (Site Settings > Site Permissions > Access Request Settings), these values are inconsistent. Furthermore, by comparing the results between what PowerShell returned and what was visible online, I found that the value for RequestAccessEmail returned by PowerShell was the most recent one - 1.  In other words, if I made changes A, B and C, in that order, PowerShell returned B while online was shown C.  The value returned by PowerShell was always one change behind.
  • To disable access requests for all sites, just set RequestAccessEmail to "" in the code routine above.

No comments: