Show and Hide Columns in SharePoint List Forms Using PowerShell

show and hide Field in SharePoint List Using PowerShell

Today, we’re gonna introduce a PowerShell Script that helps you to Show and Hide Columns in SharePoint List Forms Using PowerShell.

Show and Hide Column in SharePoint List Forms Using PowerShell

In this post, we’ll explore

You might also like to read Hide Column in SharePoint List Form Using JQuery


Show and Hide Columns in SharePoint List Forms Using PowerShell

Consider you have a SharePoint list with custom columns as shown below:

Show and Hide Columns in SharePoint List Forms Using PowerShell

And you would like to show or hide specific columns in SharePoint forms like

  • New Form.
  • Edit Form.
  • Display Form.
  • Or All Forms (as a bulk action).

In this case, you have two options to do that

Here, we’ll introduce a simple PowerShell script function that you can use to easily show and hide columns in SharePoint New, Edit and Display forms or All forms with one action.

ShowHide_SPColumn -SiteURL "http://SiteURL" -ListTitle "List Title" -FieldName "Field Name" -FormType "New" -Show $false

Important Notes

Before we getting started to use this PowerShell script, you should first be aware of the following:

  • You can’t show or hide the system generated columns (Modified, Created …etc) using PowerShell.
  • You can only show or hide custom columns like Title, a new custom column that you have already created.
  • Hide required columns in New form will not prevent your form to be submitted but it will save empty values as shown below.
Show and Hide Column in SharePoint List Forms

PowerShell Script: Show and Hide Columns in SharePoint List Forms

In this section, we’ll explain in details how you can use ShowHide_SPColumn cmdlet to Show and Hide Columns in SharePoint List Forms using PowerShell.

Required Parameters

To be able to use ShowHide_SPColumn cmdlet, you should provide the below parameters correctly:

  • -SiteURL: The SharePoint site URL that holds the list that you would like to show or hide specific columns on it.
  • -ListTitle: The target list display name.
  • -FieldName: The field display name that you would like to show or hide.
  • -FormType: The type of SharePoint form that you need to show or hide your field. This parameter can be set to the belowvalues:
    • New: if you would like to hide or show a specific field in the new form.
    • Edit: if you would like to hide or show a specific field in the edit form.
    • Display: if you would like to hide or show a specific field in the display form.
    • All: if you would like to hide or show a specific field in all SharePoint list forms.

Note: If you have provided an incorrect -FormType value, it will be accepted and applied only to the new form by default.

  • -Show: set this parameter to $false if you would like to hide the column and to $true to re-show it back.

Features

Verification

This script ensure that you have provided a correct data for

  • Site URL.
  • List Title.
  • Field Name.

If you have provided wrong List Title or incorrect site URL, you will get the below warning message:

Show and Hide Columns in SharePoint List Forms Using PowerShell - Test1

It also ensures that the provided field name exists in the current SharePoint list.

If you have provided incorrect field name, it will detect that and hence it will show all the fields in the provided list to let you review and decide which field you need to show or hide as shown below:

Check if the field in the SharePoint List Using PowerShell

Prompt Message to continue

After applying the verification test on the list you will be asked to confirm to proceed or not .

Are you sure you would like to Hide ‘your Field Name’ column in ‘Form Type’ in ‘your List’ list?[y/n]:

Confirm to Show or Hide Field in SharePoint List Forms Using PowerShell

Bulk Show and Hide Column in All SharePoint List Forms

You can easily show and hide columns in ALL SharePoint list forms by running one line of command when you set -FormType parameter to “All”.

Usage

Use this script to show or hide columns in SharePoint List Forms by doing the following:

Steps

Run Windows PowerShell as Administrator
  • Open the downloaded script.
  • Run ShowHide_SPColumn cmdlet with your own information.
Syntax
ShowHide_SPColumn -SiteURL "http://SiteURL" -ListTitle "List Title" -FieldName "Field Name" -FormType "Display or New or Edit" -Show $false

Hide Column in SharePoint list Form Using PowerShell

In this section, we will apply our script on a list called “Show and Hide SharePoint Column” that located in a site “http://epm:19812

Show and Hide Columns in SharePoint List Forms Using PowerShell

Hide Columns in SharePoint New Form Using PowerShell

This is the new form before running our script.

Hide Columns in SharePoint New Form Using PowerShell

Syntax

ShowHide_SPColumn -SiteURL "http://SiteURL" -ListTitle "List Title" -FieldName "Field Name" -FormType "New" -Show $false

Example

This example will hide a field called “Project Description” in New form in a SharePoint list called “Show and Hide SharePoint Column” that hosted in a site “SiteURL “http://epm:19812”

ShowHide_SPColumn -SiteURL "http://epm:19812" -ListTitle "Show and Hide SharePoint Column" -FieldName "Project Description" -FormType "New" -Show $false
Hide SharePoint Columns in New Form Using PowerShell

Output

The “project description” field is hidden in the SharePoint new form successfully as shown below:

Hide SharePoint Column in New Form Using PowerShell

Note: to re-show this field back, just set -Show parameter to $true

Hide Column in SharePoint Edit Form Using PowerShell

This is the edit form before running our script.

Hide Columns in SharePoint New Form Using PowerShell

Syntax

ShowHide_SPColumn -SiteURL "http://SiteURL" -ListTitle "List Title" -FieldName "Field Name" -FormType "Edit" -Show $false

Example

This example will hide a field called “Project Description” in Edit form in a SharePoint list called “Show and Hide SharePoint Column” that hosted in a site “SiteURL “http://epm:19812”

ShowHide_SPColumn -SiteURL "http://epm:19812" -ListTitle "Show and Hide SharePoint Column" -FieldName "Project Description" -FormType "Edit" -Show $false
Hide SharePoint Column in Edit Form Using PowerShell

Output

The “project description” field is hidden in the SharePoint edit form successfully as shown below:

Hide SharePoint Column in New Form Using PowerShell

Note: to re-show this field back, just set -Show parameter to $true

Hide Column in SharePoint Display Form Using PowerShell

This is the display form before running our script.

Hide SharePoint Column in Display Form Using PowerShell

Syntax

ShowHide_SPColumn -SiteURL "http://SiteURL" -ListTitle "List Title" -FieldName "Field Name" -FormType "Display" -Show $false

Example

This example will hide a field called “Project Description” in Display form in a SharePoint list called “Show and Hide SharePoint Column” that hosted in a site “SiteURL “http://epm:19812”

ShowHide_SPColumn -SiteURL "http://epm:19812" -ListTitle "Show and Hide SharePoint Column" -FieldName "Project Description" -FormType "Display" -Show $false
Hide SharePoint Field in Display Form Using PowerShell

Output

The “project description” field is hidden in the SharePoint display form successfully as shown below:

Hide SharePoint Column in List Display Form Using PowerShell

Note: to re-show this field back, just set -Show parameter to $true

Hide Column in All SharePoint List Forms

As bulk action, you can show and hide SharePoint column for all List forms

Syntax

ShowHide_SPColumn -SiteURL "http://SiteURL" -ListTitle "List Title" -FieldName "Field Name" -FormType "All" -Show $false

Example

This example will hide a field called “Project Description” in All SharePoint forms in a SharePoint list called “Show and Hide SharePoint Column” that hosted in a site “SiteURL “http://epm:19812”

ShowHide_SPColumn -SiteURL "http://epm:19812" -ListTitle "Show and Hide SharePoint Column" -FieldName "Project Description" -FormType "All" -Show $false
Hide Column in All SharePoint List Forms

Note: to re-show this field back, just set -Show parameter to $true


Conclusion

In conclusion, we have introduced a PowerShell script that would help you to easily show and hide columns in SharePoint list forms.

Downlaod
Applies To
  • SharePoint 2019.
  • SharePoint 2016.
  • SharePoint 2013.
  • SharePoint 2010.
You might also like to read
Have a Question?

If you have any related questions, please don’t hesitate to ask it at deBUG.to Community.

Leave a Comment

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

Scroll to Top