Update Master Page for apps
some times you can face issues with apps due to change in master pages
# if no arguments added display error and exit
if ($args.Length -eq 0)
{
Write-Host -ForegroundColor Red "Missing Required Argument"
Write-Host -ForegroundColor Red "Usage - 'ResetAppMasterPages <<site collection url>>' "
Exit 0
}
$siteCollUrl =$args[0]
Add-PSSnapin Microsoft.SharePoint.PowerShell -ERRORAction SilentlyContinue | Out-Null
#start logging
$LogFile = "$($FarmConfig.Farm.ScriptConfig.ScriptLoggingFolder)$($MyInvocation.MyCommand.Name.Replace('.ps1',''))-$(Get-Date -Format yyyy-MM-dd_h-mm-ss).txt"
Start-Transcript -Path $LogFile -Force
Start-SPAssignment -Global
$site = $null
try
{
$site = Get-SPSite $siteCollUrl
#iterate through all the webs
foreach ($web in $site.AllWebs)
{
#check if the web is an app web
if ($web.IsAppWeb -eq $true)
{
try
{
Write-Host "Updating master page for : " $web.Url
#Below lines will help to keep history of old master page urls in the log
Write-Host "Old MasterUrl : " $web.MasterUrl
Write-Host "Old CustomMasterUrl : " $web.CustomMasterUrl
#update master page to app.master
$web.CustomMasterUrl = $web.ServerRelativeUrl + "/_catalogs/masterpage/app.master"
$web.MasterUrl = $web.ServerRelativeUrl + "/_catalogs/masterpage/app.master"
$web.Update()
Write-Host -ForegroundColor Green "Successfully updated master page for : " $web.Url
}
catch
{$_}
finally
{
if ($null -ne $web)
{
# need to dispose web from allwebs property
$web.Dispose()
}
}
}
}
}
catch
{$_}
finally
{
if ($null -ne $site)
{
# dispose site object
$site.Dispose()
}
}
Stop-SPAssignment -Global
Stop-transcript
The error happens when the master page of the parent site is
applied to the app web of the Sharepoint App.
In my case I could reproduce this by reapplying the master page
in the UI and selecting the “Reset all subsites to inherit the master
page option”.
# if no arguments added display error and exit
if ($args.Length -eq 0)
{
Write-Host -ForegroundColor Red "Missing Required Argument"
Write-Host -ForegroundColor Red "Usage - 'ResetAppMasterPages <<site collection url>>' "
Exit 0
}
$siteCollUrl =$args[0]
Add-PSSnapin Microsoft.SharePoint.PowerShell -ERRORAction SilentlyContinue | Out-Null
#start logging
$LogFile = "$($FarmConfig.Farm.ScriptConfig.ScriptLoggingFolder)$($MyInvocation.MyCommand.Name.Replace('.ps1',''))-$(Get-Date -Format yyyy-MM-dd_h-mm-ss).txt"
Start-Transcript -Path $LogFile -Force
Start-SPAssignment -Global
$site = $null
try
{
$site = Get-SPSite $siteCollUrl
#iterate through all the webs
foreach ($web in $site.AllWebs)
{
#check if the web is an app web
if ($web.IsAppWeb -eq $true)
{
try
{
Write-Host "Updating master page for : " $web.Url
#Below lines will help to keep history of old master page urls in the log
Write-Host "Old MasterUrl : " $web.MasterUrl
Write-Host "Old CustomMasterUrl : " $web.CustomMasterUrl
#update master page to app.master
$web.CustomMasterUrl = $web.ServerRelativeUrl + "/_catalogs/masterpage/app.master"
$web.MasterUrl = $web.ServerRelativeUrl + "/_catalogs/masterpage/app.master"
$web.Update()
Write-Host -ForegroundColor Green "Successfully updated master page for : " $web.Url
}
catch
{$_}
finally
{
if ($null -ne $web)
{
# need to dispose web from allwebs property
$web.Dispose()
}
}
}
}
}
catch
{$_}
finally
{
if ($null -ne $site)
{
# dispose site object
$site.Dispose()
}
}
Stop-SPAssignment -Global
Stop-transcript
Comments
Post a Comment