4

I have created a list and added some new fields in my sharepoint site. I now want to add my new fields onto the All Items view using Powershell is this possible? I tried :

$viewFields = New-Object System.Collections.Specialized.StringCollection
$viewFields.Add("Title")
$viewFields.Add($myFieldPrivacyStatementurl)
$viewFields.Add($myFieldIsActive)
$viewFields.Add($myFieldSortOrder)

#
# View Name
$viewName = “All Privacy Statements”
#
# Finally – Provisioning the View
$myListView = $myList.Views.Add($viewName, $viewFields, "", 100, $True, $False)
#

$myListView.DefaultView = $True
$myListView.Update()
#
$myList.OnQuickLaunch = $True
$myList.Update()

But this just adds a new all items view any help would be appreciated

8

Get the web and list:

$w = Get-SPWeb http://localhost
$l = $w.Lists["My list"];

This is how you select the view "All items":

$view = $l.Views | ? { $_.Title -eq 'All items' }

Then just add fields:

$view.ViewFields.Add($hereGoesFieldName);

And update view:

$view.Update();
2

Retrieve All Items view by using $myList.DefaultView if it is a default view or by using the index $myList.Views["All Items"]. Then add fields to it and finally update it.

$defaultView = $myList.DefaultView;
// Repeat this line for all fields
$defaultView.ViewFields.Add($myList.Fields["FieldName"]);

$defaultView.Update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.