December 27, 2012

Powershell - Add newly added field to all views


#Add-PSSnapin Microsoft.SharePoint.PowerShell
cls
$web = Get-SPWeb -Identity "url of web"
#list of views which needs to be changed
$views = @("All Documents","View1","View2")

$list = $web.GetList("ListUrl")
foreach($vwName in $views)
{
    $vw = $list.Views[$vwName]
    #Add new field
    $vw.ViewFields.Add("fieldName")
        #position is 0 based
    $vw.ViewFields.MoveFieldTo("fieldName",2)
    
    $vw.Update()
    Write-Host $vwName, "Updated"
}
 
If you have any questions you can reach out our SharePoint Consulting team here.

No comments:

Post a Comment