Bulk Creation of SharePoint Site Columns via Powershell

When we’re dealing with large implementations or want to re-create functionality in another site, it is often useful to automate the creation of a large number of Site Columns in SharePoint. I’ve created this Powershell script to do just that.

First of all, we need to create a CSV file with all the information for the Site Columns that we want. It must have the following format:

 

BulkSiteColumnsCSVexample

With the .CSV file populated, we just need to run the following script:

$SiteURL = Read-Host “Input Site URL: ”
$CSVPath = Read-Host “Input path to CSV: ”
$site = Get-SPSite -Identity $SiteURL
$csv = import-csv -Path $CSVPath
$web = $site.RootWeb
Foreach ($ID in $csv)
{
$XML = ‘<Field
Type=”‘+$ID.Type+'”
Name=”‘+$ID.Name+'”
Description=”‘+$ID.Description+'”
DisplayName=”‘+$ID.DisplayName+'”
StaticName=”‘+$ID.StaticName+'”
Group=”‘+$ID.Group+'”
Hidden=”‘+$ID.Hidden+'”
Required=”‘+$ID.Required+'”
Sealed=”‘+$ID.Sealed+'”
ShowInDisplayForm=”‘+$ID.ShowInDisplayForm+'”
ShowInEditForm=”‘+$ID.ShowInEditForm+'”
ShowInListSettings=”‘+$ID.ShowInListSettings+'”
ShowInNewForm=”‘+$ID.ShowInNewForm+'”>
</Field>’
write-host “”
write-host $XML
write-host “”
$web.Fields.AddFieldAsXML($XML)
write-host “”
}

This will run through each item in the CSV and create a Site Column in the specified site with the properties as dictated by the CSV

I hope you find it useful.

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s