Hi We have a listViewA(col1,col2,col3) and listViewB(col1,col2,col3) on the same form library.

Now the requirement is to modify these existing listviews, so that they do not contain the old column but other columns using powershell commands.

listViewA(col4,col5,col6) listViewB(col4,col5,col6)

 #Get destination site and list
$web = Get-SPWeb "http://portal/sites/testsite"
$list = $web.GetList(($web.ServerRelativeUrl.TrimEnd("/") + "/Shared Documents"))

$viewTitle = "V1" #Title property
#Add the column names from the ViewField property to a string collection
$viewFields = New-Object System.Collections.Specialized.StringCollection
$viewFields.Add("col4") > $null
$viewFields.Add("col5") > $null
$viewFields.Add("col6") > $null

#Query property
$viewQuery = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE'/></OrderBy>"
#RowLimit property
$viewRowLimit = 50
#Paged property
$viewPaged = $true
#DefaultView property
$viewDefaultView = $false

#Create the view in the destination list
$newview = $list.Views.Add($viewTitle, $viewFields, $viewQuery, $viewRowLimit, $viewPaged, $viewDefaultView)
Write-Host ("View '" + $newview.Title + "' created in list '" + $list.Title + "' on site " + $web.Url)

Above is the code i will using, where v1 is the existing view that needs to be modified. I believe that this code will create new columns to the existing view, but will it help delete the old columns? How can i efficiently get my task done?

1 Answer 1


Try to integrate below code in your existing script :

$spWeb = Get-SPWeb http://servernamehere/docs/test/sitename
$spList = $spWeb.GetListFromUrl("EMails/Forms/AllItems.aspx")
$spView = $spList.DefaultView

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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