Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

How to Change Column Type in SharePoint List using PowerShell

$
0
0
Recently, There was a requirement to change column types from "Single line of text" to "Multiple Lines of Text" in multiple lists. Needless to say, PowerShell is the most efficient way to get such things done in bulk.

Here is the PowerShell Script to change column type in SharePoint 2010 programmatically:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the Web where Lists Live
$web= Get-SPWeb "http://sharepoint.crescent.com/sites/Operations/"

#Define Array to hold Lists Names to Scan
$ListNames = ("Design Documents", "Project Closure", "Metrics")

#Column to Change
$ColumnName ="Closing Notes"

#Iterate through provided Lists
foreach($ListName in $ListNames)
{
#Get the List
$list = $web.Lists.TryGetList($ListName)
if( $list -ne $null)
{
#Check if the list has our target column to change
if($list.fields.ContainsField($ColumnName))
{
#Get the Column to Change
$column = $List.Fields[$ColumnName]

#Change the Column type to "Multiple Lines of Text"
$column.Type = [Microsoft.SharePoint.SPFieldType]::Note
$column.Update()
Write-Host "Field type updated on: $($List.Title)"
}
}
}

$web.Dispose()

Done! Check SPFieldType in MSDN to get all available column types in SharePoint.

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>