I'm making a script in Powershell for get all the documents within a document library and its folders and subfolders, I'm doing something like this:
$DocumentLibary = "TestDocuments"
$LibLists = "test"
function GetFiles ($Lists)
{
foreach ($file in $Lists.RootFolder.Files)
{
Write-Host "`t" $file.Name
}
#Loop through all subfolders and call the function recursively
foreach ($SubFolder in $lists.RootFolder.SubFolders)
{
if($SubFolder.Name -ne "Forms")
{
Write-Host "`t" $file.Name
GetFiles ($Subfolder)
}
}
}
$rootWeb = $clientContext.Web
$LibLists = $rootWeb.lists.getByTitle($DocumentLibary)
$clientContext.Load($rootWeb)
$clientContext.load($LibLists)
$clientContext.Load($LibLists.RootFolder)
$clientContext.Load($LibLists.RootFolder.Files)
$clientContext.ExecuteQuery()
GetFiles $LibLists
But with this I only get the documents in the root of the document library.
Any idea ? what am I missing?
Thanks!