Today, we’re gonna introduce a PowerShell Script that helps you to Show and Hide Columns 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
Consider you have a SharePoint list with custom columns as shown below:
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
- Using JQuery to hide or disable column in SharePoint forms,
- Using PowerShell script to can show and hide columns in SharePoint forms.
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.
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:
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:
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]:
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
- Download the PowerShell Script: Show and Hide Column in SharePoint List Forms from GitHub
- 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
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“
This is the new form before running our script.
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
Output
The “project description” field is hidden in the SharePoint new form successfully as shown below:
Note: to re-show this field back, just set -Show parameter to $true
This is the edit form before running our script.
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
Output
The “project description” field is hidden in the SharePoint edit form successfully as shown below:
Note: to re-show this field back, just set -Show parameter to $true
This is the display form before running our script.
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
Output
The “project description” field is hidden in the SharePoint display form successfully as shown below:
Note: to re-show this field back, just set -Show parameter to $true
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
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
- PowerShell Script: Show and Hide Column in SharePoint List Forms.
- PowerShell Script: SharePoint Farm Scan Report.
- Follow and Browse SharePoint PowerShell Scripts GitHub Repository.
Applies To
- SharePoint 2019.
- SharePoint 2016.
- SharePoint 2013.
- SharePoint 2010.
You might also like to read
- Show / Hide fields based on choice field selection using JQuery in SharePoint.
- Set Rich Multiple Line Text Field as Read Only in SharePoint.
- Hide The Content-Type Column In Edit Form In SharePoint.
- Set Field as Read-only in Edit Form In SharePoint.
Have a Question?
If you have any related questions, please don’t hesitate to ask it at deBUG.to Community.