This PowerShell script will provi​sion a new list remotely using ListCreationInformation.CustomSchemaXml.

Further below is an example of the XML to be fed in, which is the tricky part.​

param(​

[Parameter(Mandatory = $true)][string]$webUrl,

[Parameter(Mandatory = $true)][string]$schemaXmlFilePath,

[Parameter(Mandatory = $true)][int]$listTemplateId

)

 

$csom = [Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SharePoint.Client’)

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext $webUrl

$ctx.Load($ctx.Web.Lists)

$ctx.Load($ctx.Web.ListTemplates)

$ctx.ExecuteQuery()

 

$schemaXml = [xml] (Get-Content $schemaXmlFilePath)

$template = $ctx.Web.ListTemplates | WHERE { $_.ListTemplateTypeKind -eq $listTemplateId }

$info = New-Object Microsoft.SharePoint.Client.ListCreationInformation

$info.Title = $schemaXml.List.Title

$info.Url = $schemaXml.List.Url

$info.CustomSchemaXml = $schemaXml.OuterXml

$info.TemplateType = $listTemplateId

$info.TemplateFeatureId = $template.FeatureId

 

$list = $ctx.Web.Lists.Add($info)

$ctx.ExecuteQuery()​

This script works against SharePoint 2010 and SharePoint 2013, but requires PowerShell v3 or higher.

​How to structure the XML

Simply grabbing the SchemaXml from an existing list does not work.

An easy way to start is to use Visual Studio. Add a list to a SharePoint project and then grab the Schema.xml file. It can be used as-is. Here is an example generated when choosing the Custom List template.

http://schemas.microsoft.com/sharepoint/”>

 

 

 

 

 

 

 

 

http://schemas.microsoft.com/sharepoint/v3″ StaticName=”Title” MaxLength=”255″ />

 

 

 

 

main.xsl

30

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

main.xsl

clienttemplates.js

30

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Softlanding
Written By:

Softlanding

More By This Author

Azure Sentinel Demo

Microsoft Azure Sentinel is a scalable, cloud-native, security information event management (SIEM) and security orchestration...

Read More