Búsqueda de sitios web

Cambiar la página maestra en SharePoint usando PowerShell


Requisito: Cambiar la página maestra para las colecciones de sitios de SharePoint.

Después de un proyecto de rediseño de marca, tuve el requisito de cambiar las páginas maestras en los sitios existentes. Branding en nuevos sitios que se van a crear. Pero para los sitios existentes, tenemos que cambiar las páginas maestras manualmente.

SharePoint: configurar la página maestra usando PowerShell

Cambiemos la página maestra en SharePoint usando PowerShell.


Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

#Get the Web
$web = Get-SPWeb "https://intranet.crescent.com/branding"

#Prepare the Custom Master page URL
$WebURL = $web.ServerRelativeUrl.TrimEnd("/")
$MasterPageURL = $WebURL+"/_catalogs/masterpage/crescentv1.master"

#Set Default and Custom Master pages
$web.MasterUrl = $MasterPageURL
$web.CustomMasterUrl = $MasterPageURL

#Apply Changes
$web.Update() 

Cambiar la página maestra de SharePoint 2013 usando PowerShell
¿Qué tal todos los sitios en una colección de sitios? Aquí está el script de PowerShell en SharePoint 2013 para cambiar la página maestra.


#Variable for Site collection
$SiteURL ="https://intranet.crescent.com"

#Get the Site object
$site = Get-SPSite $SiteURL

#Iterate through each web
foreach ($web in $site.AllWebs)
{
   #Prepare the Custom Master page URL
   $WebURL = $web.ServerRelativeUrl.TrimEnd("/")
   $MasterPageURL = $WebURL+"/_catalogs/masterpage/crescentv1.master"

   $web.MasterUrl = $MasterPageURL;
   $web.CustomMasterUrl = $MasterPageURL;
 
   $web.Update();

   Write-Host "Master page set for: $web.Url
}

Podemos modificar el código anterior para aplicar la página maestra a toda la aplicación web, ¡incluso a toda la granja de SharePoint!

Artículos relacionados