Replace-RequestAccessEmail
February 21, 2013 1 Comment
Retrieve and update/change access request on all the sites/webs inside a web application that has my email as the access request. Some sites have a branch site managers email group that need to be used as well. Sourced from PowerShell script to update Access Request Email Address for multiple sites and webs and Windows PowerShell: Build a Better Function.
function Replace-RequestAccessEmail { <# .SYNOPSIS Update Access Request containing Specified Email .DESCRIPTION Find all the Access Request Settings that have a specified email and replace it with either another account, another account and the Branch Site Managers email, or remove from string .EXAMPLE Replace the email address with a new address and the Branch Site Managers email Replace-RequestAccessEmail -webapp "https://WEBAPP1" -email "Joe.Cool@email" -replace "SPADMIN@email" -SPSiteMgrs .EXAMPLE Removes the email address from the string Replace-RequestAccessEmail -webapp "https://WEBAPP1" -email "Joe.Cool@email" .PARAMETER webapp Web Application to cycle through. .PARAMETER email Email in Access Request Setting to locate .PARAMETER replace (OPTIONAL) Email to use as replacement - leave off to have email removed from string. .PARAMETER SPSiteMgrs (OPTIONAL) Include to replace using Site Managers email based on Site Collection #> [CmdletBinding()] param ( [Microsoft.SharePoint.PowerShell.SPWebApplicationPipeBind]$webapp, [string]$email, [string]$replace, [switch]$SPSiteMgrs ) process { $webapplication = Get-SPWebApplication -Identity $webapp [string]$trimSites = $webapplication.URL $trimSites = $trimSites + "sites/" foreach($site in $webapplication.Sites) { foreach($web in $site.AllWebs) { if ($web.HasUniquePerm -and $web.RequestAccessEnabled) { if ($web.RequestAccessEmail -like "*$email*") { $siteCollection = $web.Site | %{$_.URL} $siteCollection = $siteCollection.TrimStart($trimSites) Write-Host "Site Collection: " $siteCollection Write-Host "On Web" $web.Title ", URL" $web.URL Write-Host "`tAccess requests go to :" $web.RequestAccessEmail If($SPSiteMgrs.IsPresent) { If(!$replace.IsPresent) { #Default with Admin Account $replace = "SPADMIN@EMAIL" } switch ($siteCollection) { "BRANCH_A" {$requestAccessEmail = "$replace; BRANCH_A.SPSiteMgr@EMAIL"} "BRANCH_B" {$requestAccessEmail = "$replace; BRANCH_B.SPSiteMgr@EMAIL"} "BRANCH_C" {$requestAccessEmail = "$replace; BRANCH_C.SPSiteMgr@EMAIL"} default {$requestAccessEmail = "$replace"} } } else { $requestAccessEmail = $web.RequestAccessEmail $reqeustAccessEmail = $requestAccessEmail.ToLower() $email = $email.ToLower() $requestAccessEmail = $requestAccessEmail.Replace($email,$replace) } # If the Request Access Email would be blank, set to SharePoint Admins Email If ($requestAccessEmail -eq "") { $requestAccessEmail = "SPADMIN@EMAIL" } Write-Host "`t***Will Update Request Access Email to: "$requestAccessEmail "***" $web.RequestAccessEmail = $requestAccessEmail $web.Update() } } } #end ForEachWeb #Dispose of the site object $site.Dispose() } #end ForEachSite } #end Process } #endFunction