Friday, October 16, 2015

Delete Field from SharePoint List using poweshell

#Load SharePoint User Profile assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.PowerShell") | out-null
Add-PSSnapin Microsoft.Sharepoint.Powershell -ErrorAction:SilentlyContinue

#Global variables
$webUrl = "http://contoso:1515/"
#List Name
$ListName = "PollQuestions"
# Deleted Field Internal Name
$fieldName = "Test"

$spWeb = Get-SPWeb -Identity $webUrl
$list = $spWeb.Lists[$ListName]
$listFields = $list.Fields
$listFields.Delete($fieldName);
$list.Update();

No comments:

Post a Comment