How to set the list view scope in SharePoint Online using PnP PowerShell

I have a documents library named “Shared Documents” in which I want to set “Show all items without folders” property for “All Documents” list view.

 

You can download setup files from the releases section of the PnP PowerShell repository.

Copy the below script and paste it in a notepad. Save the file as SetListView.ps1.

  1. # Input Parameters  
  2. $siteURL="https://c986.sharepoint.com/sites/dev"  
  3. $listName="Shared Documents"  
  4. $viewName="All Documents"  
  5.   
  6. Connect to SharePoint Online site  
  7. Connect-PnPOnline –Url $siteURL –Credentials (Get-Credential)  
  8.   
  9. # ViewScope Enum  
  10. $viewScope=[Microsoft.SharePoint.Client.ViewScope]::Recursive  
  11.   
  12. Update the list view  
  13. Set-PnPView -List $listName -Identity $viewName -Values @{Scope=$viewScope}  

ViewScope enum:

 
 
Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"  

 

folderlocation – SetListView.ps1 file location

Run the following command

  1. >.\SetListView.ps1  

Reference: Set-PnPView

Thus in this blog, you saw how to set the list view scope in SharePoint Online using PnP PowerShell.