I'm trying to display the versions of each item in a folder that contains sub folders.
Since I don't necessarily want to scan a whole SPO list, I specified to start in a certain folder, e.g. '/Documents/test'
. If this starting folder contains a sub folder, e.g. '/Documents/test/subtest
' I'm also able to retrieve it and its contents. However if this sub folder contains one more level my script doesn't retrieve it and its contents. I don't know what I can do to drill down recursively.
I appreciate any tips.
$site = "https://finnova-my.sharepoint.com/sites/contoso"
$folderPath = "/Documents/test"
Connect-PnPOnline $site -Credentials $credential
$spoCred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials
$credential.UserName, $credential.Password
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext $site
$ctx.Credentials = $spoCred
$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
$serverRelativeUrl = (Get-PnPList Documents).RootFolder.ServerRelativeUrl
$folder = $web.GetFolderByServerRelativeUrl($site+$folderPath)
$ctx.Load($folder)
$ctx.Load($folder.Folders)
$ctx.ExecuteQuery()
ForEach ($subFolder in $folder.Folders)
{
$ctx.Load($subFolder.Files)
$ctx.ExecuteQuery()
ForEach ($file in $subFolder.Files)
{
$file.Name
$version = $file.Versions
$ctx.Load($version)
$ctx.ExecuteQuery()
$versionCount = $version.Count
$versionCount
}
}