SharePoint Power Shell Script: Add Fields / Columns in existing View

Scenario:

We need to add fields / columns in existing view via power shell script

Resolution:

$site New-Object -TypeName “Microsoft.SharePoint.SPSite” -ArgumentList “Site URL”

$web $site.OpenWeb()

$list $web.Lists[“List Name”]

$fieldsName = “Created,Created By,Title,Content Type”

$fields $fieldNames.Split(‘,’)

$view $list.Views[“View Name”]

foreach ($fieldName in $fields)

{

$field $list.Fields[$fieldName]

$view.ViewFields.Add($field)

}

$view.Update()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: