TwitterLinkedInBlog

Wednesday, May 8, 2013

PowerShell - Delete Fields From Content Types


# DELETE A FIELD FROM A LIST CONTENT TYPE
$web = Get-SPWeb http://localhost
$list = $web.Lists["MyList"]
$listContentTypes = $list.ContentTypes
$listContentType = $listContentTypes["My List Content Type"]
$listFieldLink = $listContentType.FieldLinks["MyListFieldInternalName"]
$listContentType.FieldLinks.Delete("MyListFieldInternalName")
$listContentType.Update()


# DELETE A FIELD FROM A SITE CONTENT TYPE
$web = Get-SPWeb http://localhost
$webContentTypes = $web.ContentTypes
$webContentType = $webContentTypes["My Web Content Type"]
$webFieldLink = $webContentType.FieldLinks["MyWebFieldInternalName"]
$webContentType.FieldLinks.Delete("MyWebFieldInternalName")
$webContentType.Update()