$ ListItemCollection = @()仅允许将表达式用作管道的第一个元素

时间:2019-05-20 18:30:32

标签: xml csv sharepoint sharepoint-2010

尝试运行此脚本时出现以下错误。

PS C:\WINDOWS\system32> C:\AIR\air.ps1
At C:\AIR\air.ps1:13 char:1
+ $ListItemCollection = @()
+ ~~~~~~~~~~~~~~~~~~~
Expressions are only allowed as the first element of a pipeline.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline

我正在尝试从内部Sharepoint 2010系统导入数据。用于构建表单的应用程序将一些数据保存为XML。我正在尝试将XML数据导入CSV文件。

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentyContinue

$siteurl = "http://XXX.XXX.XXX.XXX:7000/accidentreports"

$listname = "Accident Incident Report"

$web = Get-SPWeb -identity $siteurl

$list = $web.Lists[$listname]|

$ListItemCollection = @()


$list.Items | foreach {

$ExportItem = New-Object PSObject

$ExportItem | Add-Member -MemberType NoteProperty -name "Id" -value $_["ID"]

$ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]

$ExportItem | Add-Member -MemberType NoteProperty -name "FormXml" -value $_["FormXml"]

$ListItemCollection += $ExportItem

}


#Export the results Arry to CSV file

$ListItemCollection | Export-CSV "C:\AIR\AIR.csv" -NoTypeInformation

#Dispose the web object

$web.Dispose()

我期望将XML数据导入CSV文件。

1 个答案:

答案 0 :(得分:1)

删除“ |”最后$list = $web.Lists[$listname]|