当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 更改 SharePoint 中的母版页

作者:精品下载站 日期:2024-12-14 13:45:23 浏览:15 分类:玩电脑

使用 PowerShell 更改 SharePoint 中的母版页


要求:更改 SharePoint 网站集的母版页。

在品牌重新设计项目之后,需要更改现有网站上的母版页。将在新网站上创建品牌。但对于现有网站,我们必须手动更改母版页。

[玩转系统] 使用 PowerShell 更改 SharePoint 中的母版页

SharePoint:使用 PowerShell 设置母版页

让我们使用 PowerShell 更改 SharePoint 中的母版页。


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() 

使用 PowerShell 更改母版页 SharePoint 2013
网站集中的所有网站怎么样?以下是 SharePoint 2013 中用于更改母版页的 PowerShell 脚本。


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

我们可以修改上面的代码来将母版页应用于整个Web应用程序,甚至整个SharePoint场!

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯