PowerShell script to add column to SharePoint list
PowerShell script to add column to SharePoint list. It' useful when you want to make changes in your SharePoint list in test area and then to repeat in productive one.
Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue $web = get-spweb "http://spdev/mysite/" cls $list = $web.Lists["myListName"] $newColumn = "<Field Type='Text' DisplayName='New Column' Required='TRUE' MaxLength='20' Name='newColumn' Description='New column added from powershell'/>" $list.Fields.AddFieldAsXml($newColumn, $true, [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView) $list.Update()