Reputation: 21
I have a powershell script that creates Folders in SharePoint online. I'm using Add-PnPFolder to do so. By default the new folder view is sorted by Name. I wish to change the default view so that it is sorted by the field Created. Manually this can easily be done. But programmatically I have no clue how to change the view of a PnPFolder. Here's the part of the code where I create the folder...
Connect-PnPOnline -ClientId $SPO_AppId -ClientSecret $SPO_AppSecret -Url $siteUrl
$connection = Get-PnPConnection
if ($connection)
{
Add-PnPFolder -Folder /Team/Acquisition -Name Approvals -Connection $connection
}
Get-PnPView only works on PnPLists, not on PnPFolders unfortunately.
Upvotes: 0
Views: 342
Reputation: 2091
The order of the items displayed in view is configured in the view property, not in item property.
Code example to change the sorting property of a view:
$Context = Get-PnPContext
$view=Get-PnPView -List "Documents" -Identity "2B0E08F9-39AC-4553-9343-FDDF3551F77A"
$Context.Load($View)
$Context.ExecuteQuery()
$Query= "<OrderBy><FieldRef Name='Created' /></OrderBy>"
$View.ViewQuery = $ViewQuery
$View.ViewQuery = $QUERY
$View.Update()
$Context.ExecuteQuery()
Upvotes: 0