0

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.

henk
  • 21
  • 2

1 Answers1

0

The order of the items displayed in view is configured in the view property, not in item property. enter image description here

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()
Amos
  • 2,030
  • 1
  • 5
  • 9
  • Hi Amos Thanks for your response. The thing is, I'm trying to change the view of a single PnPFolder. So there is no -List I can refer to in the Get-PnPView command. – henk Jan 25 '21 at 14:05
  • The view displayed in the folder is the list view, you cannot set a separate view for the folder. – Amos Jan 26 '21 at 08:29