Saturday, 7 June 2014

Powershell | Get SharePoint 2010 Custom Error and Access Denied pages

A simple script, run this on any SharePoint server in a farm and it will return all set error and access denied pages for all web applications:

Scenario: Audit of farm setup

Script:
<#
.Synopsis
   Gets all set error and access denied pages for all webapps in the current farm
.EXAMPLE
   get-sperrorpages
#>

function get-sperrorpages()
{
    $snapin = Get-PSSnapin | Where-Object { $_.Name -eq 'Microsoft.SharePoint.Powershell'}
    if ($snapin -eq $null)
    {      
        Write-Host "Loading SharePoint Powershell Snapin"
        Add-PSSnapin "Microsoft.SharePoint.Powershell"
    }

    Start-SPAssignment -global
get-spwebapplication | ForEach-Object {
Write-Host "Web Application: $_" -foregroundcolor Green
Write-Host " - Error Page Set:" $_.GetMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::Error)
Write-Host " - Access Denied Page Set:" $_.GetMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::AccessDenied)
Write-Host ""
}

    Stop-SPAssignment –global
}

Output:
PS C:\dev\scripts\audit> .\get-errorpages.ps1
Web Application: SPWebApplication Name=intranet.devnet.local
 - Error Page:
 - Access Denied Page:

Web Application: SPWebApplication Name=extranet.devnet.local
 - Error Page: /_layouts/Devnet.Local/Error.aspx
 - Access Denied Page: /_layouts/Devnet.Local/AccessDenied.aspx

Web Application: SPWebApplication Name=internet.devnet.local
 - Error Page: /_layouts/Devnet.Local/Error.aspx
 - Access Denied Page: /_layouts/Devnet.Local/AccessDenied.aspx

Web Application: SPWebApplication Name=edit.internet.devnet.local
 - Error Page: /_layouts/Devnet.Local/Error.aspx
 - Access Denied Page: /_layouts/Devnet.Local/AccessDenied.aspx

As you can see from that execution my farm has four web applications, three are publicly accessible so i have set custom error and access denied pages, the fourth is internal only so there is no need for any custom branded pages

No comments:

Post a Comment