【发布时间】:2018-11-27 09:52:54
【问题描述】:
我正在尝试将一些数据从共享点列表导出到 csv,但出现此错误:
$ListItemCollection |导出-CSV "D:\LX.csv" -NoTypeInformation
Method invocation failed because [System.Management.Automation.PSObject] doesn't contain a method named 'op_Addition'.
At line:20 char:2
+ $ListItemCollection += $ExportItem
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
代码真的很简单
$URL = "https://mysite"
$List = "Page Contents"
$Web = Get-SPWeb $URL
$web
$spList = $Web.Lists[$List]
$Items = $spList.GetItems()
$listItems = $spList.Items
foreach($item in $listItems) {
$ExportItem = New-Object PSObject
$ExportItem | Add-Member -MemberType NoteProperty -name "PageID" -value $item["PageID"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "Html Component" -value $item["Html Component"]
#Add the object with property to an Array
$ListItemCollection += $ExportItem
}
【问题讨论】:
-
为什么要
foreach并附加项目?为什么不只是$splist.Items | Select-Object PageID,"Html Component"? -
另外,你在哪里实例化
$ListItemCollection?它是什么样的物体? -
刚刚从另一个博客复制了示例代码
-
复制代码时最好参考代码的来源。
标签: powershell sharepoint