Friday, 20 August 2010

Show and hide columns in SharePoint list forms with PowerShell

One of the great things about PowerShell with SharePoint 2010 is the ability to configure settings that are not available through the browser interface by writing a simple script, rather than having to load up Visual Studio and develop a custom application to access the Object Model. This article covers how to set properties on columns in order to show or hide them from specific list forms.

The following table taken from MSDN shows the properties available to us:

ShowInDisplayForm Gets or sets a Boolean value that specifies whether the field is displayed in the form for displaying list items.
ShowInEditForm Gets or sets a Boolean value that specifies whether the field is displayed in the form that is used to edit list items.
ShowInListSettings Gets or sets a Boolean value that specifies whether the field is displayed in the page for customizing list settings.
ShowInNewForm Gets or sets a Boolean value that specifies whether the field is displayed in the form that is used to create list items.
ShowInVersionHistory Gets or sets a Boolean value that specifies whether the field is displayed in the page for viewing list item versions.
ShowInViewForms Gets or sets a Boolean value that specifies whether the field is displayed in pages that are used to view list data.

For this example, I am going to disable the ShowInEditForm properties for a column called “Test Column” that I have created directly in a document library (I’ll deal with site columns later). Here is a screenshot of the edit form when I upload a new document to the library or edit the properties of an existing document:


I then run the following PowerShell Script:

#Get the web, list and column objects
$web = Get-SPWeb http://portal
$list = $web.Lists["Shared Documents"]
$column = $list.Fields["Test Column"]

#Change the ShowInEditForm property and update objects
$column.ShowInEditForm = $false

Now when I edit the properties of the document, the Test Column is no longer there:


However, because the ShowInDisplayForm property is still set to true, the column does appear when I view the properties of a document:


The script is different if you want to achieve the same thing with a site column. I used the following script to modify the ShowInEditForm property of a site column called “Test Site Column”, which can be added to document libraries and lists directly, or through a content type. Note that the new ShowInEditForm property setting will apply to all document libraries, lists and content types where the site column has been added:

#Get the web and site column objects
$web = Get-SPWeb http://portal
$column = $web.Fields["Test Site Column"]

#Set the PushChangesToLists property for the changes to be applied
#to lists where the column has already been added
$column.PushChangesToLists = $true

#Change the ShowInEditForm property and update objects
$column.ShowInEditForm = $false


  1. Thanks!

    This was very helpfull!

  2. Great article. However, if I make it not display in the editform, can I edit the column programmatically?

    I'm finding that when I set it to not display, when user's create new documents, I'm unable to retrieve the value for that column.

  3. Brad - interesting. I haven't tried the scenario you mention, although I'm surprised that you can't get the value. You could always try switching the ShowInEditForm property on using your code, checking access to the column and then switching it off again. It wouldn't be a long term solution, but would be interesting to see if you could get the value at least.

  4. Thanks for your response Phil. I've actually tried that. It's like the value doesn't get created when the column is optional because it doesn't think it exists? Not sure.

    What's worse is if there's a default value, the default value will still show on the front end. Very frustrating and I can't find a solution.

  5. Dear.I am very honored to introduce a recuva android products to you, it is very useful and
    free,and professional technical support.THANK YOU !

  6. I like this blog! In return, I want to share some cheap ray ban sunglasses with you.

  7. the author of this site must be a PowerShell and SP geek. Otherwise how come he can create thousands of PS scripts which makes SP developers' life easier!!!
    Words will not be sufficient for saying thanks!!
    Hats Off !!! _/\_

  8. También puede visitar una tienda de ladrillo y mortero de Michael Kors o su sitio web y comprar directamente un bolso Michael Kors desde allí. Usar un bolso de Michael Kors les permite a los demás reconocer que el habitante urbano educado toma la moda realmente con seriedad. Los bolsos de hombro son particularmente refinados y elegantes.

    {Bolsas Michael Kors Precios | Bolsos Michael Kors Outlet | Michael Kors Rebajas}

    En vacker konstnärlig skapelse av vävt läder, som ger ett skalskaligt utseende - liknar en snakeskin eller fiskhud, linjer utsidan av påsen. Läderens bältros är små läderringar. Det finns också gyllene accenter på väskan. Slutresultatet är svagt liknar kedjepost.

    {Michael Kors Rea | Michael Kors Väska Rea | Michael Kors Plånbok}

  9. عند تنفيذ هذه الخطوة في غرفة المعيشة، ونستضيف شخص بالغرفة يجب أن يتحرك بكل راحة وسهولة ويكون منظر الغرفة مريح للنظر ويعطي شعور بأناقة المكان وترتيبه واتساعه.
    شركة نقل عفش و اثاث بالسعودية
    شركة نقل عفش من الرياض الى الاردن
    شركة نقل اثاث من الرياض الى الاردن

  10. فقد يلجئ القلة لطرق تقليدية لمقاتلة هذه الحشرات وذلك يكون السبب في مشاكل أضخم صحية للموجودين بالمكان أو تلف بعض قطع العفش الى منحى عدم الوصول للمكافحة التامة للحشرات وترجع مرة ثانية.
    شركة مكافحة النمل الابيض بجدة
    شركة مكافحة حشرات بجدة
    شركة رش مبيدات بجدة
    افضل شركة رش مبيدات

  11. A beautiful purse or handbag from Coach Outlet Online can last for many years, and represent a great overall value.
    There are Michael Kors Bags Outlet in a large number of shopping malls located throughout the country.
    Cheap Michael Kors Bags is a great way to determine which models best suit your needs.
    Official Coach Factory Outlet Online all strive to provide comfort and convenience for their owners and the seams are double-stitched for maximum durability.
    Michael Kors Factory Store, has one of the most popular handbag and accessory lines on the market today.
    Coach Handbags Wholesale says a lady is classy, elegant and sophisticated.
    Coach Store Near Me trends come and go, but a Coach stands the test of time.
    The official Michael Kors Handbags On Sale Outlet regularly posts various handbags being offered for sale.
    Compare your Coach Bags On Sale Outlet to the logo provided on the website to make sure it is similar.
    All Michael Kors Outlet Online Store have serial numbers.

  12. No matter what type of Michael Kors Bags Outlet each individual got, they all had one thing in common. We all know that getting something on sale is like winning a mini lottery, but to find a name brand handbag like Michael Kors Black Friday Sale for instance, discounted is like a slice of heaven on earth. I have personally attacked my husband with hugs and kisses when finding Official Coach Outlet Online at discounted prices.

    Michael Kors Factory Outlet stores can be found in malls all over. MK Outlet and other Coach merchandise can also be found in some boutiques. Inspired by the same material baseball gloves are made from, these Coach Bags On Sale Online are versatile and stylish. Since it's conception, the Michael Kors Handbags Outlet has been produced into a variety of designs, colors, shapes, and styles that have won top pick of millions of women the world over.

    New Michael Kors Bags are the most sought after handbag. Since Coach Outlet Online is one of the most recognized name brands in the world of fashion, you will find A-list celebrities down to small girls wearing them.

    tags:Coach Outlet|Coach Bags Factory Outlet|Coach Purses Outlet

  13. This internet site is my breathing in, very great pattern and perfect content. Find out today ‘s Celebrity birthdays and discover who shares your birthday. We make it simple and entertaining to learn about celebrities.