SharePoint Online: How to Hide Columns from List using PowerShell?

Requirement: Hide a Field in SharePoint Online using PowerShell.

In a project request list, when a user fills the form, we want to hide the “Status” column by default and then have a workflow to populate the status of the particular request. Similarly, for the Edit column, but show it only on the View form. So, How to hide a column from the SharePoint Online list?

SharePoint Online Hide Column from a list using PowerShell:

Here is the PowerShell script to hide list columns from the SharePoint Online list.

#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"
  
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/prjects/"
$ListName="ProjectRequest"
$FieldName = "Status" #Display Name

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
  
    #Get the web, List and Field objects
    $Web=$Ctx.Web
    $List=$web.Lists.GetByTitle($ListName)
    $Field = $List.Fields.GetByTitle($FieldName)

    #Hide the column from New & Edit forms
    $Field.SetShowInEditForm($False) 
    $Field.SetShowInNewForm($False) 
    $Field.UpdateAndPushChanges($True)
    $Ctx.ExecuteQuery()
     
    Write-host -f Green "List Field hidden Successfully!"
}
Catch {
    write-host -f Red "Error hiding List Column: " $_.Exception.Message
}

This PowerShell hides the specific field from the list’s New form and Edit forms!

sharepoint online hide column

SharePoint Online: Hide a column in the new item form using PnP PowerShell

Use this PnP PowerShell script to hide a column from the SharePoint Online list:

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"
$ListName = "Projects"
$FieldName =  "Status"

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

#Get the Field
$Field = Get-PnPField -List $ListName | Where {$_.Title -eq $FieldName}

#Hide the field from New Form
$Field.SetShowInNewForm($False)
#$Field.SetShowInEditForm($True)
Invoke-PnPQuery

You can also use the Set-PnPField cmdlet to hide a field from the SharePoint Online list:

#Connect to SharePoint Online
Connect-PnPOnline -Url "https://crescent.sharepoint.com/sites/marketing" -Interactive

#Hide a column
Set-PnPField -List "Config" -Identity "Title" -Values @{Required=$False;Hidden=$True}

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!

Leave a Reply

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