Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm encountering a strange problem on SharePoint 2007 where the following script correctly enumerates files and folders on my QA and DEV sites, but not on my Production site. Why is SPWeb.GetFolder() behaving this way?


$Site = new-Object Microsoft.SharePoint.SPSite("http://fully/qualified/path/to/doc/lib")
$web = $Site.RootWeb
$rootFolder = $web.GetFolder("http://fully/qualified/path/to/doc/lib")

Write-Host $rootFolder.Url

Write-Host "File Count: " $rootFolder.Files.Count
foreach($files in $rootFolder.Files)
    Write-Host $files.Name

Write-Host "Folder Count: "  $rootFolder.SubFolders.Count
foreach($folders in $rootFolder.SubFolders)
    Write-Host $folders.Name

It is correctly outputting the path, but returning 0 for the file and folder counts on PROD. I'm not getting any exceptions.

In each case for DEV, QA, and PROD, I'm running with an account with full "god-like" privileges. In each case, no exceptions are being thrown. Verifying that the site exists for each environment confirms that the items exist.

As a workaround, due to desperation, I've added an extra GetList() call passing in the same full URL prior to calling GetFolder(). This seems to work for PROD, but I'm at loss to explain why. The idea came from this blog post.

share|improve this question
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.