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
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.