Export data from SharePoint 2010 List using Management Shell

AID: 9182
  • Status: Published

2660 points

  • Byeldawg
  • TypeTutorial
  • Posted on2012-01-12 at 10:36:04
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Data and save it in a csv file.  In Part2, I will explain how to schedule it on a periodic basis.  

After some research I found Roi Kolbinger's blog "I Will Share my Point: Export SharePoint 2010 List to Excel with PowerShell.  The problem with this is that it will only extract the Title field.  I was able to create a PowerShell script to extract the data using Roi's script as the base for my script and with a little help from a developer, named Miguel Wood,  who told me "Yes.  The .Items will only export the Title column.  To export the list, try creating and using a PSObject."  
Now that we have some background information, let’s create a SharePoint Management Shell script to extract the data from a SharePoint 2010 List and into a csv file.

1.  Open notepad and paste the following code customizing it for your environment.
$MyWeb = Get-SPWeb "http://sitename"
$MyList = $MyWeb.Lists["ListName"]
$exportlist = @()
$Mylist.Items | foreach {
$obj = New-Object PSObject -Property @{
            “Column1” = $_["Column Name in SharePoint"]
           "Column2" = $_["Column Name in SharePoint"]                  
}
$exportlist += $obj
$exportlist | Export-Csv -path 'C:\FilePath\Filename.csv'
}
*Notes:   Http://sitename is the url to the site where the list is located and ListName is the name of the List that contains the data you would like to extract.
Column1 and Column2 are the names of the columns you want to be named in the CSV file.  Column Name in SharePoint is the actual column named stored in the SharePoint Database. For instance if you renamed the Title column to Name, your code should resemble the following:
“Name” =$_[“Title”}
Export-Csv – path is the location you want the script to save the file.
2.  After you have made the corrections/customizations Save the file with extension ps1.  IE:  Export.ps1.
3.  Place or copy the file to a drive located on the SharePoint Server you will run the script.  We utilize our Application Server.
4.  Now that we have created the script, manually run it to test the file.  RDP to the server, open a SharePoint Management Shell prompt, go to the directory where you saved the file and run the following command: .\Filename.ps1

Now that you know how to extract data from a SharePoint 2010 list using SharePoint Management Shell, you can also create a scheduled task to run the file using the Windows Task Scheduler.  I will explain you accomplish this in Part 2. Coming Soon I hope.

References:  
Roi Kolbinger - I Will Share my Point: Export SharePoint 2010 List to Excel with PowerShell (http://iwillsharemypoint.blogspot.com/2011/02/export-sharepoint-2010-list-to-excel.html)

Miguel Wood - Developer
Asked On
2012-01-12 at 10:36:04ID9182
Tags

SharePoint 2010

,

List

,

PowerShell

,

Management Shell

,

Export

Topic

MS SharePoint

Views
1774

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top MS SharePoint Experts

  1. ACH1LLES

    358,298

    Wizard

    0 points yesterday

    Profile
    Rank: Genius
  2. JamieMcAllister

    189,161

    Guru

    0 points yesterday

    Profile
    Rank: Sage
  3. teylyn

    170,328

    Guru

    900 points yesterday

    Profile
    Rank: Genius
  4. ivan_vagunin

    156,400

    Guru

    0 points yesterday

    Profile
    Rank: Sage
  5. QPR

    123,685

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  6. Tehzar

    100,639

    Master

    0 points yesterday

    Profile
    Rank: Guru
  7. svetaye

    75,681

    Master

    0 points yesterday

    Profile
    Rank: Guru
  8. tedbilly

    71,150

    Master

    0 points yesterday

    Profile
    Rank: Genius
  9. quihong

    52,832

    Master

    0 points yesterday

    Profile
    Rank: Sage
  10. dp_expert

    49,160

    0 points yesterday

    Profile
    Rank: Wizard
  11. colly92002

    41,560

    0 points yesterday

    Profile
    Rank: Master
  12. clayfox

    39,400

    0 points yesterday

    Profile
    Rank: Genius
  13. milindsaraswala

    36,835

    0 points yesterday

    Profile
  14. RainerJ

    31,840

    1,000 points yesterday

    Profile
    Rank: Master
  15. abhitrig

    31,218

    0 points yesterday

    Profile
    Rank: Wizard
  16. dhawalseth

    30,268

    0 points yesterday

    Profile
  17. ImaCircularSaw

    29,438

    0 points yesterday

    Profile
    Rank: Guru
  18. martusha

    25,478

    0 points yesterday

    Profile
  19. zephyr_hex

    21,624

    0 points yesterday

    Profile
    Rank: Genius
  20. FastFngrz

    21,414

    0 points yesterday

    Profile
    Rank: Guru
  21. livanescu

    20,100

    0 points yesterday

    Profile
  22. danshady

    18,870

    0 points yesterday

    Profile
  23. CloudedTurtle

    18,050

    0 points yesterday

    Profile
    Rank: Master
  24. jessc7

    17,102

    0 points yesterday

    Profile
    Rank: Sage
  25. JoeKlimis

    16,318

    0 points yesterday

    Profile
    Rank: Master

Hall Of Fame