0

I am attempting to dump all data from my Sharepoint Lists to csv. I seem to have the code working at about 95% the way I want it, but I am missing the Created By, Created On, Modified By, and Modified On dates. How do I capture those fields?

Here is my current code for one of my lists:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$url = "http://internalweburl/subsite"
$listName = "List1"
$path ="c:\Exports\$listname.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

Without having to list each individual field, I can't seem to find a way to include those. This would be a huge undertaking as we have many lists I need to export, and I don't have the time to go through each and document all the fields. Any help would be greatly appreciated.

1 Answer 1

0

$list = $web.Lists["Your List Name"];

$fields = $list.Fields;

$list.Fields | select InternalName | Export-Csv -path $path;

The above should work, right using SPList.Fields ? Refer the answer here link to answer

1
  • This just gives me a list of the column titles. I need to export all the rows AND include the Modified/Created fields. Commented Jun 26, 2018 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.