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

[玩转系统] 使用 PowerShell 将查找字段添加到 SharePoint 列表

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

使用 PowerShell 将查找字段添加到 SharePoint 列表


要求:用于将查找字段添加到 SharePoint 列表的 PowerShell 脚本:

场景:您有一个名为“父项目”的父列表和一个名为“项目里程碑”的子列表。子列表中的“父项目名称”字段是从父列表的“项目名称”字段中查找的。

[玩转系统] 使用 PowerShell 将查找字段添加到 SharePoint 列表

PowerShell 将查找字段添加到 SharePoint 列表

使用此 PowerShell 脚本将查找列添加到 SharePoint 列表:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#configuration parameters
$WebURL="https://portal.crescent/Projects/"
$ParentListName="Parent Projects"
$ChildListName="Project Milestones"

$ParentLookupColumnName="Project Name"
$ChildLookupColumnName="Parent Project Name"

#Get the Parent and Child Lists
$Web = Get-SPWeb $WebURL
$ParentList = $web.Lists[$ParentListName]
$ChildList = $web.Lists[$ChildListName]

#Check if Field exists already
if(!$childList.Fields.ContainsField($ChildLookupColumnName))
{
    #sharepoint powershell - create lookup field
    $ChildLookupColumn = $ChildList.Fields.AddLookup($ChildLookupColumnName,$ParentList.id,$False)
    $ChildLookupColumn = $ChildList.Fields[$ChildLookupColumnName]

    #Setup lookup Field property
    $ChildLookupColumn.LookupField = $ParentList.Fields[$ParentLookupColumnName]
    #$ChildLookupColumn.AllowMultipleValues=$true
    $ChildLookupColumn.update()
    write-host "Lookup field added successfully!" -f green
}
else
{
    write-host "Field Exists already!" -f red
}

就这样!我们在 SharePoint 列表中使用 PowerShell 创建了一个查找列。要在 SharePoint Online 列表中添加查找列,请使用:如何使用 PowerShell 在 SharePoint Online 列表中创建查找列?

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

取消回复欢迎 发表评论:

关灯