1

I'm using the PowerShell script below to create views on a SharePoint Online document library with subfolders. The script creates the view, but does not display the files contained in the subfolder. The script creates a view that 'shows all items without folders'.

The Excel file in the screenshot is the only file in the subfolder 0002TestFolder. Unfortunately, I'm not very familiar with PowerShell and don't know what the script requires to create the view correctly.

#Config Variables
$SiteURL = "https://XXXX.sharepoint.com/sites/TestTeamSite"
$ListName = "Documents"
$ViewName = "0002TestFolder"
$ViewFields = @("DocIcon", "Name", "Modified", "Modified By")
$ViewColumns = "DocIcon", "Name", "Modified", "Modified By"
$Query = "<OrderBy><FieldRef Name='Title' /></OrderBy><Where><Leq><FieldRef Name='Modified' /><Value Type='DateTime'><Today/></Value></Leq></Where>"
 
#Get Credentials to connect
#$Cred = Get-Credential
 
Try {
    #Connect to PNP Online
    Connect-PnPOnline -Url $SiteURL -UseWebLogin
 
#sharepoint online pnp powershell create view
Add-PnPView -List $ListName -Title $ViewName -ViewType Html -Fields $ViewFields -Query $Query -ErrorAction Stop
Set-PnPView -List $ListName -Identity $ViewName -Values @{Scope=[Microsoft.SharePoint.Client.ViewScope]::Recursive}
Write-host "View '$ViewName' Created Successfully!" -f Green
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

Subfolder View:

enter image description here

All Documents View:

enter image description here

0

1 Answer 1

0

Setting Recursive to Scope works fine for me. It shows all the files in folders & it's subfolders.

You might want to check the filters if all expected files are not shown in library view.

Possible values for Scope:

  • FilesOnly — Show only the files of a specific folder.
  • Recursive — Show all files of all folders.
  • RecursiveAll — Show all files and all subfolders of all folders.

If Scope attribute is not set, the view displays only the files and subfolders of a specific folder.

Source: View element (List) - Elements and attributes

Other references:

  1. ViewScope enumeration
2
  • Thank you for your response. However, this has not resolved the issue. The view is not displaying the files within the subfolder.
    – Patti Love
    Apr 23, 2021 at 12:52
  • I have tried this at my end & library view was showing the files from up to 3 levels of subfolders. Apr 23, 2021 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.