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
$column.Update()
$list.Update()
$web.Dispose()
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
$column.Update()
$web.Update()
$web.Dispose()