SharePoint Online: How to Hide a Column in Content Type using PowerShell?

Requirement: Hide a Column from Content Type in SharePoint Online.

How to Hide a Column using Content types in SharePoint Online?

Columns can be hidden at the content type or the list level in SharePoint. You can hide a column from appearing in list forms, such as: NewForm.aspx, EditForm.aspx, DispForm.asxp using the content type. Enable the content type first by going to:

  • Go to List Settings >> Advanced Settings >> enable the “Allow management of content types”  check box.

Once content types are enabled, you can hide any field of that content type.

  • Go to List Settings again >> Under Content Types, Click on Item content type (or whatever content type applicable) 
  • Click on the Title column (or the column you wish to hide) under the columns group >> Click on the “Hidden” option.
    SharePoint Online: How to Hide a Column in Content Type using PowerShell

The specific column won’t appear on any of the forms listed above. You can also remove the column from “Views” by removing them from the list views.

PowerShell to hide a Column from List Content Type in SharePoint Online:

Let me show you how you can hide a column from the content type in SharePoint Online using PowerShell.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#function to Hide Column From List Content Type in SharePoint Online
Function Hide-ColumnFromContentType()
{ 
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $ContentTypeName,
        [Parameter(Mandatory=$true)] [string] $ColumnName
    )

    Try {
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        
        #Get the List
        $List = $Ctx.Web.Lists.GetByTitle($ListName)
        $Ctx.Load($List)
        $Ctx.ExecuteQuery()

        #Get the content type
        $ContentTypes = $List.ContentTypes
        $Ctx.Load($ContentTypes)
        $Ctx.ExecuteQuery()
        $ContentType = $ContentTypes | Where {$_.Name -eq $ContentTypeName}

        #Get the Field link from content type
        $FieldLinks =$ContentType.FieldLinks
        $Ctx.Load($FieldLinks)
        $Ctx.ExecuteQuery()
        $FieldLink = $FieldLinks | Where {$_.Name -eq $ColumnName}

        #Hide the Field link
        $FieldLink.Hidden = $True
        
        #Update Content type
        $ContentType.update($False)
        $Ctx.ExecuteQuery()

        Write-host "Column Hidden from the Content Type Successfully!" -ForegroundColor Green  
    }
    Catch {
        write-host -f Red "Error Hiding Column in Content Type!" $_.Exception.Message
    } 
} 

#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
$ContentTypeName="Item"
$ColumnName="Priority"

#Call the function 
Hide-ColumnFromContentType -SiteURL $SiteURL -ListName $ListName -ContentTypeName $ContentTypeName -ColumnName $ColumnName

Setting the field “Hidden” hides it from all list forms. Instead, you can hide the column from specific forms such as display form with:

 $FieldLink.ShowInDisplayForm = $false 

SharePoint Online: Hide a Column in List Content Type using PnP PowerShell

Assuming the content type is already added to the given list, here is the PowerShell to hide a column from the content type as list level.

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName ="Team Documents"
$ContentTypeName ="Crescent Invoice Template V2"
$FieldName = "ProjectManager"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Client Context
$Context = Get-PnPContext
 
#Get the content type from List
$ContentType = Get-PnPContentType -Identity $ContentTypeName -List $ListName

If($ContentType)
{
    #Get the Field from Content Type
    $ContentTypeField = $ContentType.Fields.GetByInternalNameOrTitle($FieldName)
    $Context.Load($ContentTypeField)
    $Context.ExecuteQuery()
 
    #Set Hidden Property of the field
    $ContentType.FieldLinks.GetById($ContentTypeField.Id).Hidden = $True
    $ContentType.Update($False) #Update children
    $Context.ExecuteQuery()
    Write-host -f Green "Field '$($ContentTypeField.Title)' Set to Hidden!"
}
sharepoint online hidden field in content type

Similarly, You can set a column in Content type as mandatory by turning on “Required” Property. E.g.

$ContentType.FieldLinks.GetById($ContentTypeField.Id).Required = $True

PnP PowerShell to Hide a Field at Content Type Level

To hide a field from the content type, use this PowerShell script:

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ContentTypeName ="Crescent Project V2"
$FieldName = "ProjectManager" #Internal Name

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Client Context
$Context = Get-PnPContext
 
#Get the content type
$ContentType = Get-PnPContentType -Identity $ContentTypeName -ErrorAction Stop
 
#Get the Field from Content Type
$ContentTypeField = $ContentType.Fields.GetByInternalNameOrTitle($FieldName)
$Context.Load($ContentTypeField)
$Context.ExecuteQuery()
 
#Set Hidden Property of the field
$ContentType.FieldLinks.GetById($ContentTypeField.Id).Hidden = $True
$ContentType.Update($True) #Update Children 
$Context.ExecuteQuery()
Write-host -f Green "Field '$($ContentTypeField.Title)' Set to Hidden!"

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

4 thoughts on “SharePoint Online: How to Hide a Column in Content Type using PowerShell?

  • Hi Salaudeen,

    Firstly I would like to thank you for such great SharePoint resources, its been absolutely invaluable!

    I have a question I am hoping you may be able to help with:

    Do you know of a way by which we can update the default value of a field (text field for example) within a given content type using PnP?

    I have created a content type in SPO within the CTH which is consumed by many sites, I need to be able to set a unique default value for the same field in each site.

    Any info you may have is most appreciated?

    Thanks.

    Reply
  • Sir is there any way to get all the optional fields In a content type ?

    Reply
  • PnP PowerShell to Hide a Field at Content Type Level: Used this script and getting this error message.

    You cannot call a method on a null-valued expression.
    At line:16 char:1
    + $ContentTypeField = $ContentType.Fields.GetByInternalNameOrTitle($Fie …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Cannot find an overload for “Load” and the argument count: “1”.
    At line:17 char:1
    + $Context.Load($ContentTypeField)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

    You cannot call a method on a null-valued expression.
    At line:21 char:1
    + $ContentType.FieldLinks.GetById($ContentTypeField.Id).Hidden = $True
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At line:22 char:1
    + $ContentType.Update($True) #Update Children
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Field ” Set to Hidden!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *