ค้นหาเว็บไซต์

เปลี่ยนมาสเตอร์เพจใน SharePoint โดยใช้ PowerShell


ความต้องการ: เปลี่ยนหน้าหลักสำหรับคอลเลกชันไซต์ SharePoint

หลังจากโครงการออกแบบแบรนด์ใหม่ มีข้อกำหนดในการเปลี่ยนหน้าต้นแบบบนไซต์ที่มีอยู่ การสร้างแบรนด์บนไซต์ใหม่จะถูกสร้างขึ้น แต่สำหรับไซต์ที่มีอยู่ เราต้องเปลี่ยนหน้าต้นแบบด้วยตนเอง

SharePoint: ตั้งค่าหน้าหลักโดยใช้ PowerShell

มาเปลี่ยนหน้าต้นแบบใน SharePoint โดยใช้ 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() 

เปลี่ยนหน้าต้นแบบ SharePoint 2013 โดยใช้ PowerShell
แล้วไซต์ทั้งหมดในไซต์คอลเลกชันล่ะ นี่คือสคริปต์ PowerShell ใน SharePoint 2013 เพื่อเปลี่ยนหน้าหลัก


#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
}

เราสามารถแก้ไขโค้ดด้านบนเพื่อใช้หน้าหลักสำหรับแอปพลิเคชันเว็บทั้งหมด แม้แต่ฟาร์ม SharePoint ทั้งหมด!

บทความที่เกี่ยวข้อง