Tuesday, August 30, 2011

Sharepoint 2010: Hide ContentType Field using Powershell script

=================================
Hide List ContentType Field using Powershell script
======================================
$siteUrl = "http://servername/sites/P128023/"
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint") > $null
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$RootWeb = $site.RootWeb

$lookForList ="Events"
$EventsList= $RootWeb.Lists[$lookForList]

if ($EventsList -ne $null)
    {
        $MissionContentType = $EventsList.ContentTypes["Mission"]
            $field = $MissionContentType.FieldLinks["Category"]
            $field.Hidden = $true
            $MissionContentType.Update();
            $EventsList.Update()
}

if ($site) {$site.Dispose()}
if ($RootWeb){ $RootWeb.Dispose()}


==========================================================
Hide ContentType Field using Powershell script
===========================================================
$siteUrl = "http://spdev5:8002/sites/library/"
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint") > $null
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$RootWeb = $site.RootWeb


$MyContentType=$RootWeb.ContentTypes["CV"]
$MyField=$MyContentType.Fields["SAIC DOC"]
$MyContentType.FieldLinks[$MyField.Id].Hidden =$true
$MyContentType.Update($true)
write-host "updated" $field.type


if ($site) {$site.Dispose()}


if ($RootWeb){ $RootWeb.Dispose()}

2 comments:

  1. Thanks - useful snippets

    ReplyDelete
  2. Thanks a lot Surya !!!... you saved my day I have tried different ways to hide the content type column without successful.. Finally you lead me to success.. great snippet once again thanks a lot…

    ReplyDelete

Followers

Blog Archive