Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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)
$web.Dispose()

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?

share|improve this question

1 Answer

up vote 1 down vote accepted

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
$spView.ViewFields.Delete("Document_x0020_Author")
$spView.Update()
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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