add column to default view using powershell
-
Monday, April 30, 2012 8:21 PM
Hi,
I am creating new list and column using powershell. but i am unable to add these column to default view of the list. I tired using 'GetViewFromUrl' method but no luck. Can any one suggest how i can add column to default view using powershell.
Anusha
All Replies
-
Monday, April 30, 2012 9:29 PM
Hello!
Script:
$web = Get-SPWeb "http://site/" $list = $web.Lists["MyList"] $view = $list.DefaultView; $view.ViewFields.Add("FieldTitle") $view.Update()Don't happy, be worry...
- Proposed As Answer by Aviw_ Friday, May 11, 2012 8:30 AM
-
Monday, April 30, 2012 9:43 PM
Here is another option by using GetViewFromUrl
$spWeb = Get-SPWeb -Identity "http://mySharePoint" $spView = $spWeb.GetViewFromUrl("/Lists/MyList/AllItems.aspx") $spField = $spList.Fields["MyField"] $spView.ViewFields.Add($spField) $spView.Update()You can also try to use SPList object as below.
$spList = Get-SPList -Url "http://mySharePoint/Lists/MyList" $spView = $spList.Views["All Items"] $spField = $spList.Fields["MyField"] $spView.ViewFields.Add($spField) $spView.Update()
If you use SPList object, all views are loaded. If you have a list with lots of views, then first approach would be better.
백상하 - Stop hacking my blog http://blog.naver.com/agilepoint
쉐어포인트 배움터 http://sharepointkorea.com
- Edited by Sangha Baek MVPMVP Monday, April 30, 2012 10:11 PM
- Marked As Answer by Shimin Huang Friday, May 11, 2012 8:28 AM
-
Tuesday, May 15, 2012 12:32 PM
Hi Sasha,
You can try this:
$view=$list.views["All Items"]
$view.viewfields.add($list.fields["fieldname"])
$view.update()
- Marked As Answer by Sasha V Wednesday, May 16, 2012 1:06 PM

