While exporting the data from Sharepoint via Powershell into a txt/csv file, I started to think, is there a way to choose all of the columns than writing all of the columns down to the code? because there are more of them than just 4...

and what does exportlist_all do in the powershell code?

$exportlist_all = @()
$columns = @("column1","column2","column3","column4")

  • Exportlist_all just declares an empty array in your snippet Nov 26, 2013 at 7:34

3 Answers 3


With the script below you can easy export all column in a list a comma seperates file

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null 

$url = "<site url>"
$listName = "<list name>"
$path ="c:\Columns.csv"

$web = Get-SPWeb $url
$list = $web.Lists.TryGetList($listName)
$list.ContentTypes | % { $_.FieldLinks } | select Name |  Export-Csv -path $path

To export all internal name of fields in a list you can change the last line into

$list.Fields | select InternalName  |  Export-Csv -path $path
  • this code didnt work for me. it didnt update already existing .csv file at all, even thought i tried to run the code with both of the 'last line options'
    – Jori
    Nov 26, 2013 at 11:33
  • Did it write an initial file?
    – Remko
    Nov 26, 2013 at 11:34
  • Do you get an error? Maybe you entered the wrong listName? When I run the code it creates a file and writes the names into this file.
    – Remko
    Nov 26, 2013 at 11:39
  • it just wrote an empty file. and i didnt get any errors..
    – Jori
    Nov 26, 2013 at 11:48
  • strange try entering line by line in powershell and see if you have the correct list. Code has to work. I have executed the code multiple times.
    – Remko
    Nov 26, 2013 at 11:58

This script accepts 2 parameters, the web url and the output path for the csv files (you must manually create the output path if it does not exist). It then get all lists and exports them to csv files where the names are the list title + .csv (yourListTitle.csv).

Here is the script:

$web = Get-SPWeb $webUrl
write-host ("Path: " + $outPath)
foreach($list in $web.Lists)
  $exportlist = $null
  $exportlist = @()
  $list.Items | foreach {
    $hash = $null
    $hash = @{}
    foreach($fld in $_.Fields ){
      Try {
        $hash.add($fld.Title, $_[$fld.Title])
      Catch [System.Management.Automation.MethodInvocationException]
        # Eating an error caused by duplicate column names.
    write-host ("Exported: " + $_.Title)
    $obj = New-Object PSObject -Property $hash #@{
    $exportlist += $obj

  $expath = $outPath + '\' + $list.Title + '.csv'
  $exportlist | Export-Csv -path $expath #$oPath


Source: http://porchcode.blogspot.com/2013/04/exporting-sharepoint-list-items-to-csv.html

  • Andrey Ungur Ugghh...you should provide a link to the script you copied and acknowledge that it is not your work. Script copied from: porchcode.blogspot.com/2013/04/… There is a related post on importing items from the csv as well: porchcode.blogspot.com/2013/04/… Patrick O'Connor
    – user22391
    Feb 2, 2014 at 18:19
  • @PatrickO'Connor I converted your answer to a comment, and also edited this post to make it clear that this script is cited from your blog. Andrey, please try to add sources to the places you find great scripts and information on. Feb 2, 2014 at 20:01

we can also try saving the list as template with content and then later on we can create list using using that template. I am not sure about your requirement but i think it will be easier.

  • I need to export the list from Sharepoint using Powershell into a txt/csv file. Adding this to the original post
    – Jori
    Nov 26, 2013 at 6:56

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.