Hide field with Powershell (en)

HideFieldWithPowershell title en

You created a list with a bunch of columns. Great!
Now you want to hide some of them in the NewForm or EditForm. Not so great.

You can do it the quick and dirty way, open the form in SharePoint Designer, edit the form and delete the columns you don’t want to have in those forms. Well, there is a much better way of doing this. With Powershell.

It is easier, faster and more comfortable if you want to see the columns you added after that in the form. With SharePoint Designer your form has to be finished. If you add a new Column, that column will not be shown in the SharePoint Designer way. The Powershell way is the way to go here. How to do that? Follow the 6 steps and you are done!

1. First we are creating a list called “Projectlist”. If you have a list where you want to try it go directly to step 4.
Add an “Custom List”(1) (Pictures in German), give it a name (2) and add it (3).



2. Then we are adding two columns for testing purpose. The first is called “Description” and the second is called “Status”. This is the column we want to hide later on in the NewForm.
3. After adding those two columns your NewForm should look similar to this:


4. Now go to your SharePoint BackendServer. With the following script the column “Status” will be hidden in the NewForm.

Add-PSSnapin Microsoft.SharePoint.PowerShell
Start-SPAssignment -global
$web = Get-SPWeb <URL of your website, where the list is located>
$list = $web.Lists["<Listname>"]
$field = $list.Fields["<ColumnName>"]
#This Hides the column in Edit Form
#$field.ShowInEditForm = 0;
#This Hides the column in new Form
$field.ShowInNewForm = $false
Stop-SPAssignment -global

5. Open a SharePoint Management Shell as Administrator. You don’t need the SharePoint Management Shell because we are losing the Add-In, but just for learing purpose, do it.
6. Now fire the script, if you get an empty line, everything worked.


7. Now if we create a new item, the column “Status” is hidden.


Additional Information:

If you take the column from above:

$field.ShowInNewForm = $false

And change the $false into $true, the column will be visible again.
Same behaviour for the column:

#$field.ShowInEditForm = 0;

If you delete the leading “#” the code will be executed and refers to the EditForm. The values are the same as in the “ShowInNewForm” line.

Hope you liked this afraIT Shorty. If you want to stay tuned, follow me on Twitter or Facebook.

Leave a Reply

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