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

[玩转系统] 使用 PowerShell 从自定义网站模板创建 SharePoint 子网站

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

使用 PowerShell 从自定义网站模板创建 SharePoint 子网站


要求:我们创建了一个用于管理 SharePoint 中的项目的 PMO 网站模板。有一个新要求,即根据自定义网站模板创建大约 20 多个新的 PMO 子网站。

要基于网站模板创建网站,您可以选择自定义选项卡,然后从列表中选择适当的网站模板。

[玩转系统] 使用 PowerShell 从自定义网站模板创建 SharePoint 子网站

用于从自定义网站模板创建子网站的 PowerShell 脚本:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom function to create a site from site template
Function Create-SubsiteFromTemplate($SiteTitle, $ParentSiteUrl, $TemplateTitle)
{
    #Get the custom site template
    $ParentWeb = Get-SPWeb $ParentSiteUrl
    $SiteTemplates = $ParentWeb.GetAvailableWebTemplates($ParentWeb.Language)

    $CustomSiteTemplate = $SiteTemplates | Where-Object {$_.Title -eq $CustomSiteTemplateTitle}

    #URL for you new subsite
    $SiteUrl = $ParentSiteUrl + $SubsiteURL

    #create subsite without template
    $web  = New-SPWeb -Name $SiteTitle -Url $SiteUrl 

    #Apply the custom site template
    $Web.ApplyWebTemplate($CustomSiteTemplate.Name)

    Write-host "Subsite $($web.Url) has been created from template!"
}

#Call the function to create subsite
Create-SubsiteFromTemplate "Airbus 365 Project" "https://teamsites.crescent.com/projects/"  "PMO Site Template"

这将在父站点上创建 URL“airbus365project”的子站点“Airbus 365 Project”:https://teamsites.crescent.com/projects/,模板为“PMO 站点模板”。

如何从自定义网站模板批量创建子网站?


#List of sites to be created
$ProjectList = @("Data Tools", "Knowledge Village", "Service Center", "Business Reporting", "JDT Core", "EFI", "Ecore Tools")
$ParentSiteURL ="https://teamsites.crescent.com/projects/"
$SiteTemplateTitle = "PMO Site Template"

#loop through each object in the array and create subsite
foreach($Project in $ProjectList)
{
    #Call the function to create subsite
    Create-SubsiteFromTemplate $project $ParentSiteURL $SiteTemplateTitle    
}

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

取消回复欢迎 发表评论:

关灯