【问题标题】:Sharepoint - Export all data to csv with powershellSharepoint - 使用 powershell 将所有数据导出到 csv
【发布时间】:2018-12-04 15:41:49
【问题描述】:

我正在尝试使用 Thriggle See His Answer Here 提供的脚本,但遇到了一些问题。它对我正在做的事情几乎完美无缺 - 除了 - 它不会导出创建者、创建日期、修改者和修改日期。

有没有办法将这些字段添加到脚本中?

这是他的剧本:

$url = "$url"
$listName = "$list"
$path ="c:\ColumnsOfList.csv"

$web = Get-SPWeb $url
$list = $web.Lists.TryGetList($listName)
$fields = $list.ContentTypes | %{ $_.FieldLinks } | select Name, DisplayName
$items = @() #array to store objects representing list items
$list.items | %{ 
    $item = $_; 
    $hash = @{}; #hash table to store field name-value pairs
    $fields | %{ $hash[$_.DisplayName] = $item[$_.Name]  }; 
    $items += new-object psobject -Property $hash }
$items | Export-Csv -Path $path

【问题讨论】:

  • 您能否列出$list.items[0] | fl * 以查看这些属性是否已经存在?不幸的是,我没有 SharePoint 环境来测试,所以我自己不能这样做。

标签: powershell csv sharepoint


【解决方案1】:

你可以试试this one

这是我的测试代码。

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the Web
$web = Get-SPWeb -identity "http://sp:12001"

#Get the Target List
$list = $web.Lists["OrderDetails"]

#Array to Hold Result - PSObjects
$ListItemCollection = @()

 #Get All List items where Status is "In Progress"
 $list.Items | foreach {
 $ExportItem = New-Object PSObject
 $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]
 $ExportItem | Add-Member -MemberType NoteProperty -Name "OrderDate" -value $_["OrderDate"]
 $ExportItem | Add-Member -MemberType NoteProperty -name "CreatedBy" -value $_["Author"]
 $ExportItem | Add-Member -MemberType NoteProperty -name "Created" -value $_["Created"]

 #Add the object with property to an Array
 $ListItemCollection += $ExportItem
 }
 #Export the result Array to CSV file
 $ListItemCollection | Export-CSV "C:\Lee\ListData.csv" -NoTypeInformation                       

#Dispose the web Object
$web.Dispose()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 2015-01-17
    • 2013-08-26
    • 1970-01-01
    • 2013-07-15
    • 2015-02-15
    • 2015-07-25
    相关资源
    最近更新 更多