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

[玩转系统] SharePoint Online:使用 PowerShell 获取列表模板

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

SharePoint Online:使用 PowerShell 获取列表模板


要求:使用 PowerShell 在 SharePoint Online 中获取列表模板。

如何在SharePoint Online中获取列表模板?

列表模板可帮助您创建与 SharePoint Online 中的现有列表非常相似的新列表。您可以将现有列表保存为模板,以帮助用户快速入门。这篇博文将向您展示如何使用 PowerShell 获取 SharePoint Online 网站上可用的所有列表模板。

您可以从以下位置获取 SharePoint Online 中的列表模板:

  • 站点设置>>“网页设计师画廊”下的“列表模板”。

[玩转系统] SharePoint Online:使用 PowerShell 获取列表模板

PowerShell 在 SharePoint Online 中获取列表模板

如果需要获取 SharePoint Online 中的所有可用列表模板,请使用此 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"

#Custom Function to get all list templates from given site URL
Function Get-SPOListTemplates([String]$SiteURL)
{
    #Get Credentials to connect
    $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 All list templates
    $ListTemplates=$Ctx.Web.ListTemplates
    $Ctx.Load($ListTemplates)
    $Ctx.ExecuteQuery()

    #Get All Available list templates
        $ListTemplates | Select Name, Description, ListTemplateTypeKind| Sort-Object Name | Format-Table -AutoSize
}

#Variable
$SiteURL="https://crescent.sharepoint.com"

#Call the function to get all list templates
Get-SPOListTemplates $SiteURL

此脚本从给定网站集中检索所有列表模板:

Name Description Template ID Announcements A list of news items, statuses and other short bits of information. 104 Asset Library A place to share, browse and manage rich media assets, like image, audio and video files. 851 Calendar A calendar of upcoming meetings, deadlines or other events. Calendar information can be synchronized with Microsoft Outlook or other compatible programs. 106 Contacts A list of people your team works with, like customers or partners. Contacts lists can synchronize with Microsoft Outlook or other compatible programs. 105 Converted Forms List of user browser-enabled form templates on this site collection. 10102 Custom List Using a list gives you the power to share information the way you want with your team members. Create your own list from scratch, add any other columns you need, and add items individually, or bulk edit data with Quick Edit. 100 Custom List in Datasheet View A blank list which is displayed as a spreadsheet in order to allow easy data entry. You can add your own columns and views. This list type requires a compatible list datasheet ActiveX control, such as the one provided in Microsoft Office. 120 Custom Workflow Process Custom Workflow Process tracking list for this web. 118 Data Connection Library A place where you can easily share files that contain information about external data connections. 130 Data Sources Gallery for storing data source definitions 110 Discussion Board A place to have newsgroup-style discussions. Discussion boards make it easy to manage discussion threads and can be configured to require approval for all posts. 108 Document Library Use a document library to store, organize, sync, and share documents with people. You can use co-authoring, versioning, and check out to work on documents together. With your documents in one place, everybody can get the latest versions whenever they need them. You can also sync your documents to your local computer for offline access. 101 External List Create an external list to view the data in an External Content Type. 600 Form Library A place to manage business forms like status reports or purchase orders. Form libraries require a compatible XML editor, such as Microsoft InfoPath 115 Issue Tracking A list of issues or problems associated with a project or item. You can assign, prioritize and track issue status. 1100 Links A list of web pages or other resources. 103 Maintenance Log Library Template List Template that creates a document library for site collection maintenance logs 175 No Code Public Workflows Gallery for storing No Code Public Workflows 122 No Code Workflows Gallery for storing No Code Workflows 117 Pages Library A list template for creating Pages list in Publishing feature 850 Persistent Storage List for MySite Published Feed MySite MicroFeed Persistent Storage List 544 Picture Library A place to upload and share pictures. 109 Project Tasks A place for team or personal tasks. Project tasks lists provide a Gantt Chart view and can be opened by Microsoft Project or other compatible programs. 150 Promoted Links Use this list to display a set of link actions in a tile based visual layout. 170 Report Library A place where you can easily create and manage web pages and documents to track metrics, goals and business intelligence information. 433 Status List A place to track and display a set of goals. Colored icons display the degree to which the goals have been achieved. 432 Survey A list of questions which you would like to have people answer. Surveys allow you to quickly create questions and view graphical summaries of the responses. 102 Tasks A place for team or personal tasks. 171 Tasks (2010) A place for team or personal tasks. 107 Wiki Page Library An interconnected set of easily editable web pages, which can contain text, images and web parts. 119 Workflow History This list is used by SharePoint to store the history events for workflow instances. 140

PowerShell 获取 SharePoint Online 中的所有自定义列表模板

我们可以使用此脚本获取可用列表模板的列表:


#Custom Function to get all list templates from given site URL
Function Get-SPOCustomListTemplates([String]$SiteURL)
{
    #Get Credentials to connect
    $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 Custom list templates
    $ListTemplates=$Ctx.site.GetCustomListTemplates($Ctx.site.RootWeb)
    $Ctx.Load($ListTemplates)
    $Ctx.ExecuteQuery()

    #Get Custom list templates
    $ListTemplates | Select Name, baseType, ListTemplateTypeKind | Format-Table -AutoSize
}

#Variable
$SiteURL="https://crescent.sharepoint.com"

#Call the function to get all list templates
Get-SPOCustomListTemplates $SiteURL

此脚本将返回 SharePoint Online 中所有可用自定义列表模板的列表。同样,您也可以获得特定的列表模板:


#Custom Function to get all list templates from given site URL
Function Get-SPOCustomListTemplate([String]$SiteURL, [string]$ListTemplateName)
{
    #Get Credentials to connect
    $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 Custom list templates
    $ListTemplates=$Ctx.site.GetCustomListTemplates($Ctx.site.RootWeb)
    $Ctx.Load($ListTemplates)
    $Ctx.ExecuteQuery()

    #Filter Specific List Template
    $ListTemplate = $ListTemplates | where { $_.Name -eq $ListTemplateName } 
    If($ListTemplate -ne $Null)
    {
        Return $ListTemplate
    }
    else
    {
        Write-host -f Yellow "List Template Not Found:"$ListTemplateName
    }
}

#Variable
$SiteURL="https://crescent.sharepoint.com"

#Call the function to get specific list template
$Template = Get-SPOCustomListTemplate $SiteURL -ListTemplateName "Quick Links Template"

使用本文中提供的脚本,您可以快速获取 SharePoint Online 网站上可用列表模板的列表,按名称筛选它们,并在需要时使用它们,例如从自定义模板创建新列表:如何从自定义创建列表使用 PowerShell 在 SharePoint Online 中模板?

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

取消回复欢迎 发表评论:

关灯