SharePoint 2013 - Create list view with PowerShell and create filter

This is an example PowerShell script to create a list view in SharePoint with a filter on a column


#Get destination site and list
$web = Get-SPWeb "https://site"
$list = $web.GetList(($web.ServerRelativeUrl.TrimEnd("/") + "/General"))

$viewTitle = "BE" #Title property
#Add the column names from the ViewField property to a string collection
$viewFields = New-Object System.Collections.Specialized.StringCollection
$viewFields.Add("DocIcon") > $null
$viewFields.Add("LinkFilename") > $null
$viewFields.Add("Modified") > $null
$viewFields.Add("Editor") > $null
$viewFields.Add("FileSizeDisplay") > $null
#Query property
$viewQuery = '<OrderBy><FieldRef Name="LinkFilename" /></OrderBy>
                            <Where><Eq><FieldRef Name="Country" /><Value Type="Text">BE</Value></Eq></Where>'
#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()



Source: https://sharepoint.stackexchange.com/questions/158009/create-list-view-powershell-and-create-filter
Share on Google Plus

About Tom DeMeulenaere

Highly accomplished information technology professional with extensive knowledge in System Center Configuration Manager, Windows Server, SharePoint, and Office 365.
    Blogger Comment

0 comments:

Post a Comment