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

[玩转系统] 使用 PowerShell 比较 SharePoint 列表项

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

使用 PowerShell 比较 SharePoint 列表项


要求:我们有两个任务列表,其中有数百行。我想比较这两个 SharePoint 列表并从中提取差异。

解决方案:

让我们使用PowerShell脚本来比较并提取SharePoint列表之间的差异!


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Variables for Processing
$SiteURL = "https://projects.crescent.com"
$ListOneName ="Team One Tasks"
$ListTwoName ="Tasks Two Tasks"
$ColumnToCompare="Task Name"

#Get site and List objects
$Web = Get-SPWeb $SiteURL
$ListOne = $web.lists[$ListOneName]
$ListTwo = $web.lists[$ListTwoName]

#Fetch specifc Column Values from each lists to compare
$ListOneValues = @()
$ListTwoValues = @()

$ListOne.Items| foreach { $ListOneValues+= $_[$ColumnToCompare] }
$ListTwo.Items | foreach { $ListTwoValues+= $_[$ColumnToCompare] }

#Compare
Compare-Object $ListOneValues $ListTwoValues # -PassThru

输出:此处,InputObject 列给出了差异。

[玩转系统] 使用 PowerShell 比较 SharePoint 列表项

SideIndicator 只是表示差异在哪里。

  • - 差异在右侧 - 比较中的第二个对象

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

取消回复欢迎 发表评论:

关灯