Question

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()
Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top