Click here to Skip to main content
13,594,279 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 16 Aug 2014
Licenced CPOL

How to Create Custom SharePoint 2013 List using PowerShell?

, 16 Aug 2014
Rate this:
Please Sign up or sign in to vote.
How to create custom SharePoint 2013 list using PowerShell?

This post How to create custom SharePoint 2013 list using PowerShell? written by Manas Bhardwaj appeared first on Manas Bhardwaj's Stream.

SharePoint provides an interface called AddFieldAsXml. This basically creates a field based on the specified schema. Nothing fancy. Right?

However, this can be very handy when you want to create your own custom lists in SharePoint programmatically. I will be using PowerShell as an example to demonstrate how you can simply create SharePoint Lists based on plain, simple xml definitions.

To start with, I created an XML template based on which I want to create my custom list using PowerShell.

<?xml version="1.0" encoding="utf-8"?>
	<Field Type="Text" DisplayName="Name" Required="False" 

	MaxLength="255" StaticName="Name" Name="Name" />
	<Field Type="Number" DisplayName="Phone Number" 

	Required="False" MaxLength="255" 

	StaticName="PhoneNumber" Name="PhoneNumber" />
	<Field Type="DateTime" DisplayName="Date of Birth" 

	Required="False" MaxLength="255" 

	StaticName="DateOfBirth" Name="DateOfBirth" /> 	
	<Field Type="Choice" DisplayName="Annual Salary" 

	Required="False" Format="Dropdown" FillInChoice="FALSE" 

	StaticName="AnnualSalary" Name="AnnualSalary">
            <Default>0 - 10000</Default>
                <CHOICE>0 - 10000</CHOICE>
                <CHOICE>10000 - 50000</CHOICE>
                <CHOICE>50000 - 100000</CHOICE>
                <CHOICE>100000 or more</CHOICE>

In this example, I have used Text, Number, Date and Choice as the Field Types. But this could be anything which is supported by SharePoint or even your own content types. Check the documentation on MSDN for Field Element.

The next step is to read this XML file, parse it and use the AddFieldAsXml method to create fields in this list. The PowerShell snippet below does the trick. Straight and simple. Isn’t it?

Add-PSSnapin Microsoft.SharePoint.PowerShell 

function CreateList($siteCollectionUrl, $listName, $templateFile){
	$spWeb = Get-SPWeb -Identity $siteCollectionUrl 
	$spTemplate = $spWeb.ListTemplates["Custom List"] 
	$spListCollection = $spWeb.Lists 
	$spListCollection.Add($listName, $listName, $spTemplate) 
	$path = $spWeb.url.trim() 
	$spList = $spWeb.GetList("$path/Lists/$listName")
	$templateXml = [xml](get-content $templateFile)
	foreach ($node in $templateXml.Template.Field) {

$siteCollectionUrl = ""
$listName = "New Custom List"
$templateFile = "template.xml"

CreateList $siteCollectionUrl $listName $templateFile

And here is the result, just by configuration in XML file, you can create lists using PowerShell.

SharePoint Create List

Happy coding!

This post How to create custom SharePoint 2013 list using PowerShell? written by Manas Bhardwaj appeared first on Manas Bhardwaj's Stream.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Manas Bhardwaj
Netherlands Netherlands

Read my personal blog at

You may also be interested in...


Comments and Discussions

SuggestionDispose Pin
Nuno Nogueira27-Jan-15 23:20
memberNuno Nogueira27-Jan-15 23:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180618.1 | Last Updated 16 Aug 2014
Article Copyright 2014 by Manas Bhardwaj
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid