1

Is there any reasonable way to export a list definition to a text file or script so it can be used to create a new list after some tweaks to the column names, and the addition of some additional columns? I specifically am not interested in "Save list as template", and am more interested in something which can be used via Powershell. I would love it if there was something similar to a SQL "CREATE TABLE" statement at our disposal.

My use case is, I have an existing list with about 40 columns in it. This list will be used as a pre-populator in a form where a user will fill in desired changes, along with additional columns, which will be submitted to a new list based on the source list. This is in a SP2010 Server environment.

For the dual reasons of accuracy and laziness, I wish to avoid having to hand-create those 40 columns.

1

The simplest thing I can come up with is simply using a content type. You gain the flexibility of modifying lists post-creation by updating the content type definition and you can add/remove columns at your leisure in the destination list. Building a list with a content type in powershell is a cakewalk and you minimize any scripting/development complications.

You can re-use the list definition's schema xml for your content type by exporting it

http://get-spscripts.com/2011/01/export-and-importcreate-site-columns-in.html

$sourceWeb = Get-SPWeb http://portal
$xmlFilePath = "C:\Install\Script-SiteColumns.xml"

#Create Export Files
New-Item $xmlFilePath -type file -force

#Export Site Columns to XML file
Add-Content $xmlFilePath "<?xml version=`"1.0`" encoding=`"utf-8`"?>"
Add-Content $xmlFilePath "`n<Fields>"
$sourceWeb.Fields | ForEach-Object {
    if ($_.Group -eq "Custom Columns") {
        Add-Content $xmlFilePath $_.SchemaXml
    }
}
Add-Content $xmlFilePath "</Fields>"

$sourceWeb.Dispose()

Personally, I'd advise carefully recreating these fields manually for optimization purposes if you're planning on using those fields for a very long time.

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.