PowerShell+SharePoint Quickie: Export List Data

I’m packaging up some work I did for a client in a set of SharePoint features, and some of the features include list instances. In this case, I needed to package up a list instance into feature xml so it could be deployed from the administrative web interface, but I didn’t have the list data in that format. I didn’t want to enter the data by hand, and there wasn’t an easy, readily-available tool to help extract the data in the format I needed. Enter PowerShell:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = New-Object Microsoft.SharePoint.SPSite("http://mysharepointsite")
$site.RootWeb.Lists["MyList"].Items |% { "`n  {0}`n  {1}`n", $_["ID"],$_["Title"] }

This spits out XML formatted for use in a <ListInstance> element.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>