比较两个SharePoint列表在线SharePoint
我正在写一些PowerShell,并希望比较两个列表。我有List1和List2。 List1和List2都有一个代码我想比较的列。 List1具有状态列,我只想在该列等于“批准”的情况下比较两者。如果获得批准,所有List1代码都应在List2中。
$Name1= "List1"
$Name2= "List2"
$List1= Get-PnPList -Connection $Connection -Web $Web -Identity $Name1
$List2= Get-PnPList -Connection $Connection -Web $Web -Identity $Name2
$List1Items= Get-PnPListItem -Connection $Connection -Web $Web -List $List1-Fields "Code", "Overall_x0020_Status"
$List2Items= Get-PnPListItem -Connection $Connection -Web $Web -List $List2-Fields "Code"
foreach ($item in $List1Items) {
if ($item.FieldValues.Overall_x0020_Status -eq "Approved" -and $item.FieldValues.Code -eq $List2Items.FieldValues.Code)
{
Write-Host $List2Items.FieldValues.Code
}
}
谢谢!
I am writing some PowerShell and looking to compare two lists. I have List1 and List2. List1 and List2 both have a Code column I am looking to compare. List1 has a Status column and I would only like to compare the two if that column is equal to "Approved". All List1 Codes should be in List2 if Approved
$Name1= "List1"
$Name2= "List2"
$List1= Get-PnPList -Connection $Connection -Web $Web -Identity $Name1
$List2= Get-PnPList -Connection $Connection -Web $Web -Identity $Name2
$List1Items= Get-PnPListItem -Connection $Connection -Web $Web -List $List1-Fields "Code", "Overall_x0020_Status"
$List2Items= Get-PnPListItem -Connection $Connection -Web $Web -List $List2-Fields "Code"
foreach ($item in $List1Items) {
if ($item.FieldValues.Overall_x0020_Status -eq "Approved" -and $item.FieldValues.Code -eq $List2Items.FieldValues.Code)
{
Write-Host $List2Items.FieldValues.Code
}
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解,那么所需的输出是List2的所有代码,这些代码在List1中被标记为批准?
这是我对此的看法,对您现有脚本的修改最少,并且具有零优化:
输出应为list2的代码,这些代码已在List1中批准。
请注意,上面的代码效率非常低,并且将对List1中的每个项目迭代List2。这是一个更优化的版本:
If I understand correctly, the desired output is all codes from List2 that are marked as Approved in List1?
Here's my take on it, with minimal modification to your existing script, and with zero optimization:
The output should be codes from List2 that were Approved in List1.
Note that the above code is very inefficient, and would iterate over List2 for every item in List1. Here's a more optimized version: