How can I change the View of a SharePoint Online folder programmatically?

%3CLINGO-SUB%20id%3D%22lingo-sub-2071022%22%20slang%3D%22en-US%22%3EHow%20can%20I%20change%20the%20View%20of%20a%20SharePoint%20Online%20folder%20programmatically%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2071022%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3EI%20have%20a%20powershell%20script%20that%20creates%20Folders%20in%20SharePoint%20online.%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20using%20Add-PnPFolder%20to%20do%20so.%26nbsp%3B%3C%2FP%3E%3CP%3EBy%20default%20the%20new%20folder%20view%20is%20sorted%20by%20Name.%20I%20wish%20to%20change%20the%20default%20view%20so%20that%20it%20is%20sorted%20by%20the%20field%20Created.%26nbsp%3B%3C%2FP%3E%3CP%3EManually%20this%20can%20easily%20be%20done.%20But%20programmatically%20I%20have%20no%20clue%20how%20to%20change%20the%20view%20of%20a%20PnPFolder.%3C%2FP%3E%3CP%3EHere's%20the%20part%20of%20the%20code%20where%20I%20create%20the%20folder...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EConnect-PnPOnline%20-ClientId%20%24SPO_AppId%20-ClientSecret%20%24SPO_AppSecret%20-Url%20%24siteUrl%3C%2FP%3E%3CP%3E%24connection%20%3D%20Get-PnPConnection%3C%2FP%3E%3CP%3Eif%20(%24connection)%20%7B%3C%2FP%3E%3CP%3EAdd-PnPFolder%20-Folder%20%2FTeam%2FAcquisition%20-Name%20Approvals%20-Connection%20%24connection%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet-PnPView%20only%20works%20on%20PnPLists%2C%20not%20on%20PnPFolders%20unfortunately.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2071022%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Visitor

Hi

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.

0 Replies