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

[玩转系统] 使用 PowerShell 在 SharePoint Online 中获取网站模板

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

使用 PowerShell 在 SharePoint Online 中获取网站模板


要求:使用 PowerShell 在 SharePoint Online 中获取网站模板。

如何在 SharePoint Online 中获取网站模板?

网站模板是 SharePoint Online 中网站的构建块。它们定义了网站的结构、数据、功能以及外观和感觉。 SharePoint Online 提供不同的开箱即用网站模板来快速创建网站。创建网站页面上的“模板选择”部分为您提供 SharePoint Online 中的网站模板列表。

  1. 登录 SharePoint 管理中心 https://YourDomain-admin.sharepoint.com/ >> 展开站点 >> 活动站点。
  2. 单击工具栏中的“创建”按钮>>选择“其他选项”。
  3. 单击“选择模板”,然后从下拉列表中选择“更多模板”。
  4. 这将带您进入经典网站创建页面,以从各种模板中进行选择。

[玩转系统] 使用 PowerShell 在 SharePoint Online 中获取网站模板

您需要网站模板才能在 SharePoint 中创建网站。从 Web 用户界面选择网站模板很好,但如何从 PowerShell 获取 SharePoint Online 中的网站模板?

PowerShell 在 SharePoint Online 中获取网站模板

在 SharePoint Online 中创建网站或网站集时,您需要网站模板 ID。下面是用于在 SharePoint Online 中获取网站模板的 PowerShell,而 Get-SPOWebTemplate cmdlet 可获取 SharePoint Online 网站模板列表。


#Variables for Admin Center & Site Collection URL
$AdminCenterURL = "https://crescent-admin.sharepoint.com/"

#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)

#Get site template list
Get-SPOWebTemplate

这将检索 PowerShell 的 SharePoint Online 网站模板 ID 列表:

[玩转系统] 使用 PowerShell 在 SharePoint Online 中获取网站模板

虽然上面的 PowerShell cmdlet 为您提供了所有 OOTB 网站模板的列表,但如何获取自定义网站模板?

SharePoint Online:使用 PowerShell 获取自定义网站模板

以下是如何使用 PowerShell 在 SharePoint Online 中获取网站模板:


#Load SharePoint Online 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 parameter values
$SiteURL = "https://crescenth.sharepoint.com"

$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
         
#Get the Custom Site Template
$SiteTemplates = $Ctx.Site.GetWebTemplates("1033","0")
$Ctx.Load($SiteTemplates)
$Ctx.ExecuteQuery()

#Remove all users from the group
ForEach($Template in $SiteTemplates)
{
    $Template | Select Name, ID, Description
}

用于获取 SharePoint Online 网站模板的 PnP PowerShell

SharePoint Online 中的“Get-PnPWebTemplates”cmdlet 可检索所有默认 Web 模板。让我们使用 PnP PowerShell 获取 SharePoint Online 中的网站模板,包括自定义网站模板。


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get the Context & Web Objects
$ClientContext = Get-PnPContext
$Web = Get-PnPWeb

#Get All Web Templates
$WebTemplateCollection = $Web.GetAvailableWebTemplates(1033,0)
$ClientContext.Load($WebTemplateCollection)
$ClientContext.ExecuteQuery()

#Get the Template Name and Title
$WebTemplateCollection | Select ID, Name, Title

这将使用 PnP PowerShell 获取 SharePoint Online 网站模板 ID 列表。

PowerShell 的 SharePoint Online 网站模板 ID 列表

以下是 SharePoint Online 中提供的模板列表及其 ID:

IdNameTitle0GLOBAL#0Global template1STS#3Team site (no Microsoft 365 group)1STS#0Team site (classic experience)1STS#1Blank Site1STS#2Document Workspace2MPS#0Basic Meeting Workspace2MPS#1Blank Meeting Workspace2MPS#2Decision Meeting Workspace2MPS#3Social Meeting Workspace2MPS#4Multipage Meeting Workspace3CENTRALADMIN#0Central Admin Site4WIKI#0Wiki Site9BLOG#0Blog15SGS#0Group Work Site16TENANTADMIN#0Tenant Admin Site17APP#0App Template18APPCATALOG#0App Catalog Site2764ACCSRV#0Access Services Site2757ACCSVC#0Access Services Site Internal2757ACCSVC#1Access Services Site7BDR#0Document Center6001CONTENTCTR#0Content Center3400TBH#0In-Place Hold Policy Center95DEV#0Developer Site3300EDISC#0eDiscovery Center3300EDISC#1eDiscovery Case1611EXPRESS#0Express Team Site10043FunSite#0SharePoint Online Tenant Fundamental Site14483OFFILE#0(obsolete) Records Center14483OFFILE#1Records Center2009EHS#0Express Hosted Site2009EHS#2Public Publishing Portal2009EHS#1Team Site – SharePoint Online configuration40OSRV#0Shared Services Administration Site3100PPSMASite#0PerformancePoint3200BICenterSite#0Business Intelligence Center6221PWA#0Project Web App Site6215PWS#0Microsoft Project Site6000REVIEWCTR#0Review Center301RedirectSite#0Redirect Site3500POLICYCTR#0Compliance Policy Center20SPS#0SharePoint Portal Server Site21SPSPERS#0SharePoint Portal Server Personal Space21SPSPERS#2Storage And Social SharePoint Portal Server Personal Space21SPSPERS#3Storage Only SharePoint Portal Server Personal Space21SPSPERS#4Social Only SharePoint Portal Server Personal Space21SPSPERS#5Empty SharePoint Portal Server Personal Space21SPSPERS#6Storage And Social SharePoint Portal Server Personal Space21SPSPERS#7Storage And Social SharePoint Portal Server Personal Space21SPSPERS#8Storage And Social SharePoint Portal Server Personal Space21SPSPERS#9Storage And Social SharePoint Portal Server Personal Space21SPSPERS#10Storage And Social SharePoint Portal Server Personal Space21SPSPERS#11Consumer OneDrive21SPSPERS#12JIT OneDrive Business22SPSMSITE#0Personalization Site30SPSTOC#0Contents area Template31SPSTOPIC#0Topic area template32SPSNEWS#0News Site39CMSPUBLISHING#0Publishing Site53BLANKINTERNET#0Publishing Site53BLANKINTERNET#1Press Releases Site53BLANKINTERNET#2Publishing Site with Workflow33SPSNHOME#0News Site34SPSSITES#0Site Directory36SPSCOMMU#0Community area template38SPSREPORTCENTER#0Report Center47SPSPORTAL#0Collaboration Portal50SRCHCEN#0Enterprise Search Center51PROFILES#0Profiles52BLANKINTERNETCONTAINER#0Publishing Portal54SPSMSITEHOST#0My Site Host56ENTERWIKI#0Enterprise Wiki6115PROJECTSITE#0Project Site59PRODUCTCATALOG#0Product Catalog62COMMUNITY#0Community Site63COMMUNITYPORTAL#0Community Portal64GROUP#0Team site65POINTPUBLISHINGHUB#0PointPublishing Hub66POINTPUBLISHINGPERSONAL#0Personal blog66POINTPUBLISHINGPERSONAL#1Personal blog67POINTPUBLISHINGTOPIC#0PointPublishing Topic68SITEPAGEPUBLISHING#0Communication site69TEAMCHANNEL#0Team Channel69TEAMCHANNEL#1Team Channel90SRCHCENTERLITE#0Basic Search Center90SRCHCENTERLITE#1Basic Search Center10100TenantAdminSpo#0SharePoint Online TenantAdmin30003TestSite#0Test Site61visprus#0Visio Process Repository1015SAPWorkflowSite#0SAP Workflow Site

如果要查找现有网站的网站模板,请使用:如何使用 PowerShell 在 SharePoint Online 中查找网站模板?

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

取消回复欢迎 发表评论:

关灯