Monday, April 30, 2012 8:21 PM
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.
Monday, April 30, 2012 9:29 PM
$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.
Tuesday, May 15, 2012 12:32 PM
You can try this:
- Marked As Answer by Sasha V Wednesday, May 16, 2012 1:06 PM