Power Shell 将一列的值复制到另一个列表中的一列
Power Shell copy value of one column into a column in another list
我需要将列表 A 中第 1 列中的值复制到列表 B 中的第 3 列中。我可以获取脚本以将列表 A 中第 1 列中的值复制到列表 A 中的第 3 列中,但我需要复制到列表 B...
Add-PSSnapin Microsoft.Sharepoint.PowerShell -ErrorAction SilentlyContinue
$SourceWeb = Get-SPWeb http://mywebsite.com
$SourceList = $SourceWeb.Lists["MyList"]
$DestWeb = Get-SPWeb http://mywebsite2.com
$DestList = $DestWeb.Lists["MyList2"]
foreach ($SourceItem in $SourceList.items)
{
$DestItem = $destItem.items | ?{$_.ID -eq $SourceItem.ID}
if ($DestItem -ne $NULL)
{
$DestItem.SystemUpdate()
}
}
代码运行并处理但不更新...
您已尝试遍历 $destItem
以找到要更新的项目,我认为应该是 $DestList:
$DestItem = $DestList.items | ?{$_.ID -eq $SourceItem.ID}
问题是因为此时 $DestItem 为 $null 没有任何循环,因此 $DestItem 保留在 $null 并且从未进入您的 IF 语句。
我需要将列表 A 中第 1 列中的值复制到列表 B 中的第 3 列中。我可以获取脚本以将列表 A 中第 1 列中的值复制到列表 A 中的第 3 列中,但我需要复制到列表 B...
Add-PSSnapin Microsoft.Sharepoint.PowerShell -ErrorAction SilentlyContinue
$SourceWeb = Get-SPWeb http://mywebsite.com
$SourceList = $SourceWeb.Lists["MyList"]
$DestWeb = Get-SPWeb http://mywebsite2.com
$DestList = $DestWeb.Lists["MyList2"]
foreach ($SourceItem in $SourceList.items)
{
$DestItem = $destItem.items | ?{$_.ID -eq $SourceItem.ID}
if ($DestItem -ne $NULL)
{
$DestItem.SystemUpdate()
}
}
代码运行并处理但不更新...
您已尝试遍历 $destItem
以找到要更新的项目,我认为应该是 $DestList:
$DestItem = $DestList.items | ?{$_.ID -eq $SourceItem.ID}
问题是因为此时 $DestItem 为 $null 没有任何循环,因此 $DestItem 保留在 $null 并且从未进入您的 IF 语句。