Saturday, August 4, 2012

How to add column/Field to default view using powershell

In this post i will given different ways to add field to view using power shell in share point 2010 site.The first one is the basic process to add the field using power shell.In the second and final process we are used GetViewFromUrl method and splist object to add the field to view in SharePoint site .
$view=$list.views["GetAllItems"]
$view.viewfields.add($list.fields["customer"])
$view.update()
using GetViewFromUrl
$spsWeb = Get-SPWeb -Identity "http://orderssite"
$spsView = $spsWeb.GetViewFromUrl("/Lists/OrderList/GetAllItems.aspx")
$spItemField = $spList.Fields["customer"]
$spsView.ViewFields.Add($spItemField)
$spsView.Update()
Using SPList object
$spsList = Get-SPList -Url "http://orderssite/Lists/OrderList"
$spsView = $spsList.Views["GetAllItems"]
$spItemsField = $spsList.Fields["customer"]
$spsView.ViewFields.Add($spItemsField)
$spsView.Update()

No comments:

Bel