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

There is a document library called "shared documents" in the site I type at the prompt when running this script. The script returns the titles of several document libraries, but not "shared documents". Why?

[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SharePoint') 
[string]$siteUrl = $args[0]
function GetMissingParameter { $script:siteUrl = Read-Host "Enter Site URL" }  

if($args.length -eq 0) { GetMissingParameter }

$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl) 
$spWebApp = $rootSite.WebApplication

foreach($site in $spWebApp.Sites) 
{ 
    foreach($list in $site.RootWeb.lists) 
    { 
        if ($list.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary)            
        {
            Write-Host $list.title, "(", $list.BaseType, ")" 
        }
    }    
    $site.Dispose() 
} 
$rootSite.Dispose()
share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

I just created a fresh site collection with a standard team site template (that has a Shared Documents library by default ).

I used the following code and got the results listed below:

$web = Get-SPWeb http://spdevsp01/sites/test
$lists = $web.lists
foreach ($list in $lists)
{
   if ( $list.BaseType -eq 'DocumentLibrary')
   {
       write-host $list.title
   }
}
$web.dispose()

Output:

Converted Forms
Customized Reports
Form Templates
List Template Gallery
Master Page Gallery
Reporting Templates
Shared Documents
Site Assets
Site Pages
Solution Gallery
Style Library
Theme Gallery
Web Part Gallery
wfpub

Do you get the same results if you run my version of the script?

I also copied the segment of your code and hard-coded in my site URL (and put a marker to separate sites)

$rootSite = New-Object Microsoft.SharePoint.SPSite("http://spdevsp01/sites/test") 
$spWebApp = $rootSite.WebApplication

foreach($site in $spWebApp.Sites) 
{ 
    write-host "==========site", $site
    foreach($list in $site.RootWeb.lists) 
    { 
        if ($list.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary)            
        {
            Write-Host $list.title, "(", $list.BaseType, ")" 
        }
    }    
    $site.Dispose() 
} 
$rootSite.Dispose()

and I see my "Shared Documents Library" in the output.

==========site SPSite Url=http://spdevsp01/sites/test
Converted Forms ( DocumentLibrary )
Customized Reports ( DocumentLibrary )
Form Templates ( DocumentLibrary )
List Template Gallery ( DocumentLibrary )
Master Page Gallery ( DocumentLibrary )
Reporting Templates ( DocumentLibrary )
Shared Documents ( DocumentLibrary )
Site Assets ( DocumentLibrary )
Site Pages ( DocumentLibrary )
Solution Gallery ( DocumentLibrary )
Style Library ( DocumentLibrary )
Theme Gallery ( DocumentLibrary )
Web Part Gallery ( DocumentLibrary )
wfpub ( DocumentLibrary )

I am thinking it might be the way you are capturing the site via user input maybe?

enter image description here

share|improve this answer
    
Your script worked properly. Thanks for the detailed answer. –  LCountee Nov 22 '11 at 19:33
add comment

Your Answer

 
discard

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

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