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

[玩转系统] 使用 PowerShell 从 SharePoint 中的自定义列表模板创建列表

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

使用 PowerShell 从 SharePoint 中的自定义列表模板创建列表


要求:使用 PowerShell 从自定义模板创建 SharePoint 列表

如何从模板创建 SharePoint 列表?

SharePoint 中的列表模板通过在任何现有列表或库(其中包含所有列以及可选的源列表中的数据)上提供模板来节省您的时间。您可以从模板(或源列表副本)创建任意数量的副本

假设您的网站中有一个现有的列表模板,以下是如何从 SharePoint 中的列表模板创建列表。

  1. 导航到 SharePoint 站点 >> 单击“设置”齿轮图标,然后单击“添加应用程序”
  2. 在“查找应用程序”搜索框中,输入列表模板名称,例如“项目模板”。您还可以向下滚动并使用分页移至下一页(自定义列表模板将位于第二页!)并选择您的列表模板。
  3. 单击显示的自定义列表模板

    [玩转系统] 使用 PowerShell 从 SharePoint 中的自定义列表模板创建列表

  4. 为新列表提供名称,然后单击“确定”
  5. 如果您在最初创建列表模板时选择了“包含内容”,您将看到使用相同列表架构创建的新列表以及数据。

用于从列表模板创建 SharePoint 列表的 PowerShell 脚本:

让我们使用 SharePoint 中的模板和 PowerShell 创建一个列表。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Create-ListFromTemplate($WebURL, $ListName, $TemplateName)
{
    #Get the Web from URL
    $Web = Get-SPWeb $WebURL

    #Get the Specific list template
    $Template = $web.site.GetCustomListTemplates($Web) | where {$_.InternalName -match $TemplateName }

    #Check if given template name exists!
    if($Template -eq $null)
    {
        Write-host "Specified list template not found!" -f Red
        exit
    }

    #Create list using template in sharepoint 2013
    $web.Lists.Add($ListName, $ListName, $Template)
    Write-host "New List Created from Custom List template" -f DarkGreen 
}

#Variables
$WebURL="https://intranet.crescent.com"
$ListName="Project-607"
$ListTemplateName="ProjectTemplate"

#Call the function to create list from template
Create-ListFromTemplate $WebURL $ListName $ListTemplateName

此脚本从 SharePoint 中的模板 (.stp) 创建列表。

[玩转系统] 使用 PowerShell 从 SharePoint 中的自定义列表模板创建列表

这是我关于从自定义列表模板创建列表的 SharePoint Online 的另一篇文章:SharePoint Online:使用 PowerShell 从模板创建列表

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

取消回复欢迎 发表评论:

关灯