I have to export all the columns in a particular sharepoint list along with the data contained in the columns.

I am currently able to get all column names but not data. Need help with that. Below is my code.

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

$web = Get-SPWeb $url
$list = $web.Lists.TryGetList($listName)
$list.ContentTypes | % { $_.FieldLinks } | select Name |  Export-Csv -path $path
  • Do you have to do it with PowerShell? Jan 7 '16 at 13:38
  • Yes. that is the main requirement.
    – Deepika
    Jan 7 '16 at 13:39

Does it have to be CSV? If so why not just export to excel? Using a csv for multiple content types may not be the best idea especially if the content types have different fields. Also depending on what you are going to do with the output I would recommend using xml.

Anyway if I really had to do it as you require maybe something like this (a separate csv per CT makes it easier IMO):

foreach ($ct in $list.ContentTypes) {
    $csv = New-Item $path + $ct.Name + ".csv"
    foreach ($fLink in $ct.FieldLinks) {
        $fields = @()
        $fields += $fLink.Name
        $fields -Join "`t" | Out-File $csv
        $items = $list.Items
        foreach ($item in $items) {
            $row = @()
            foreach ($field in $fields) {
                $row += $item[$field]
            $row -Join "`t" | Out-File $csv -Append

Please note I have not tested this so you will probably need to tinker.

  • It ca be a excel too. Testing your solution. Will update soon.
    – Deepika
    Jan 8 '16 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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