I wanted to see which site collections in our 2010 environment are not following the rules and are deactivating the Master Page in the settings.
I have some powershell code that works just fine, and it returns back the correct information but I get a bunch of exception errors. Anybody have any suggestions on how what I might be doing wrong?
Error message:
Exception calling "GetFile" with "1" argument(s): "Value does not fall within the expected range." At line:13 char:35 + $MasterPage = $Web.GetFile <<<< ($Web.MasterUrl) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
Here is my powershell script that I am using:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get all site collections of provided web app
$SiteCollections = Get-SPWebApplication | Get-SPSite -Limit All
#Loop through all site collections
foreach($Site in $SiteCollections)
{
#Loop through all Sub Sites
foreach($Web in $Site.AllWebs)
{
#Get the Master Page
$MasterPage = $Web.GetFile($Web.MasterUrl)
if ($MasterPage.name -ne "corp.master")
{
$MasterPage.Name + " : " + $Web.Url
}
}
}
Thanks guys!