Did you know the email addresses that you configure for the Request Access functionality becomes a black hole if that employee is terminated? Unfortunately, SharePoint doesn’t know how to update this setting by itself, forcing SharePoint Admins and Site Owners to hunt down sites that have this setting activated in order to update it. The script I wrote below should help SharePoint Admins with the task of identifying where this feature is configured based on the email address that needs to get updated. It doesn’t automatically update the property for you as well but that’s easily done by creating another variable to hold the address that should be used and then assigning that variable to the property within the IF statement that outputs when the site is found. Hopefully it’ll help some of you out there. Cheers 🙂

# This script will identify sites that have the Request Access email property set to the variable. 
#
# Author: Henry Ong

######################## Start Variables ########################
$siteURL = "https://site" #URL to any site in the web application.
$emailAddressToFind = "email@email.com"
######################## End Variables ########################

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$site = new-object microsoft.sharepoint.spsite($siteURL)
$webApp = $site.webapplication
$allSites = $webApp.sites

foreach ($site in $allSites)
{
	$allWebs = $site.AllWebs

	foreach ($web in $allWebs)
	{
		if($web.RequestAccessEnabled -eq $true)
		{
			Write-Host "Evaluating " $web.URL
			if($web.RequestAccessEmail -contains $emailAddressToFind)
			{
				Write-Host "Found " $emailAddressToFind " @ " $web.URL -ForegroundColor Green
				Write-Host "Press any key to continue..."
				$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
			}
		}

		$web.Dispose()
	}
	$site.dispose()
}

write-host "Done"
Advertisements