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

[玩转系统] 使用 PowerShell 从子网站创建查找网站列

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

使用 PowerShell 从子网站创建查找网站列


创建查找字段作为网站栏已在我的另一篇文章中进行了解释:在 SharePoint 2013 中创建跨站点查找网站栏。现在需要从子网站列表中创建查找网站栏!遗憾的是,没有 UI 可以根据子网站列表值创建网站栏。只能从同一站点的列表创建查找站点栏。

PowerShell 来拯救你了!我们可以使用 PowerShell 创建引用网站集中任何网站的查找网站栏!以下是用于从另一个站点上的列表创建查找列的 PowerShell 脚本。

PowerShell 从子网站(或不同网站)列表创建查找网站列:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#Where the Source List for Lookup Exists
$ParentWebURL="https://portal.crescent.com/sales/"
$ParentListName="Regions"
$ParentLookupColumnName="Region"

#Where the Lookup Site column Going to get created
$ChildWebURL="https://portal.crescent.com"
$ChildLookupColumnName="Sales Region"
 
#Get the Parent and Child Webs and List
$ParentWeb = Get-SPWeb $ParentWebURL
$ParentList = $ParentWeb.Lists[$ParentListName]
$ChildWeb = Get-SPWeb $ChildWebURL

#Check if Field exists already
if(!$ChildWeb.Fields.ContainsField($ChildLookupColumnName))
{
    #Add Lookup Field
    $ChildLookupColumn = $ChildWeb.Fields.AddLookup($ChildLookupColumnName,$ParentList.id,$False)
    $ChildLookupColumn = $ChildWeb.Fields[$ChildLookupColumnName]
 
    #Setup lookup Field property
    $ChildLookupColumn.LookupWebId = $ParentWeb.ID
    $ChildLookupColumn.LookupField = $ParentList.Fields[$ParentLookupColumnName].InternalName
    #$ChildLookupColumn.AllowMultipleValues=$true
    $ChildLookupColumn.update()
    write-host "Lookup field added successfully!" -f green
}
else
{
    write-host "Field Exists already!" -f red
} 

此 PowerShell 脚本从另一个网站上的列表创建一个 SharePoint 查找列!顺便说一句,网站栏必须在根网站上创建才能被下面的任何子网站使用。

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

取消回复欢迎 发表评论:

关灯