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

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

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

SharePoint Online:PowerShell 从自定义模板创建子网站


要求:使用 PowerShell 从自定义网站模板创建 SharePoint Online 子网站。

如何从 SharePoint Online 中的自定义模板创建子网站?

SharePoint 模板有助于在创建新网站或页面时节省时间。您可以使用与您需要的类似的模板快速创建新站点,然后根据您的要求进行自定义。在这篇博文中,我们将展示如何从 SharePoint Online 中的自定义模板创建子网站。此外,我们还将了解如何使用 PowerShell 从 SharePoint Online 中的自定义模板创建子网站。让我们开始吧!

要从 SharePoint Online 中的模板创建子网站,请执行以下步骤:

  1. 登录您的 SharePoint Online 网站 >> 单击“网站设置”齿轮图标 >> 选择“网站内容”。
  2. 在网站内容页面上,单击“新建”>> 单击菜单中的“子网站”链接。

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

  3. 提供新子网站的名称、描述和 URL。
  4. 在“模板选择”部分下,从“自定义”选项卡中选择模板

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

  5. 指定权限、导航等其他可选设置,然后单击页面底部的“创建”按钮,即可在 SharePoint Online 中使用指定的网站模板创建子网站。

让我们看看如何使用 PowerShell 在 SharePoint Online 中使用自定义网站模板创建网站。

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

假设您已经创建了现有站点模板“PMO 站点模板 V2”,以下是用于从模板创建新站点的 PowerShell:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Set Config parameters
$SiteURL = "https://crescent.sharepoint.com/"
$SubsiteURL = "branding"
$SubsiteTitle = "Intranet Branding"
$SiteTemplateName="PMO Site Template V2"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

Try {
    #Setup the context
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Context.Credentials = $credentials

    #Get the Custom Site Template
    $SiteTemplates = $Context.Site.GetWebTemplates("1033","0")
    $Context.Load($SiteTemplates)
    $Context.ExecuteQuery()
    $Template = $SiteTemplates | Where {$_.Name -eq $SiteTemplateName}

    #Specify Subsite details and create subsite from custom template
    $Subsite  = New-Object Microsoft.SharePoint.Client.WebCreationInformation
    $Subsite.Title = $SubsiteTitle
    $Subsite.WebTemplate = $Template
    $Subsite.Url = $SubsiteURL
    $NewSubsite = $Context.Web.Webs.Add($Subsite)
    $Context.ExecuteQuery()

    Write-host "Subsite Created Successfully!" -ForegroundColor Green
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

如果您想要快速创建多个共享一些常见自定义项的网站,而不是在 SharePoint UI 中手动创建它们,这可能会很有用。这是我关于 SharePoint 本地使用 PowerShell 从自定义模板创建子网站的另一篇文章:PowerShell to Create Subsite from Custom Template in SharePoint

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

取消回复欢迎 发表评论:

关灯