locked
displaying nested list of lists and libs from a sharepoint site RRS feed

  • Question

  • I have requirement of displaying a list and libraries in a nested structure from a site collection.

    However  it is displaying the catalogs libraries, master page libarries as well.

    My code is :

    [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) > $null
    
    $SiteCollectionUrl = Read-Host "Enter a Site Collection Url: ";
    $site = new-object Microsoft.SharePoint.SPSite($SiteCollectionUrl);
    
    Write-Host $site.Url
    
    $stringweburl = $site
    function IterateWebs($stringweburl)
    {
    
    $w = $stringweburl;
    
    if($w.AllWebs.Count -gt 0)
    {
    
    foreach ($SPWeb in $w.AllWebs){
      
    Write-Host "Subsite  $($SPWeb.Url)"
    
        foreach($SPList in $SPweb.lists){
        
        if(($SPList.BaseType -eq "DocumentLibrary") -and ($List.Hidden -eq $true) )
        #if($SPList.BaseType -eq "DocumentLibrary")
        {
    
          Write-Host "DocumentLibrary $($SPWeb.Url)/$($SPList.RootFolder.Url)"
        }
        elseif(($SPList.BaseType -ne "DocumentLibrary") -and ($List.Hidden -eq $true) )
        #elseif($SPList.BaseType -ne "DocumentLibrary")
        {
            Write-Host "List $($SPWeb.Url)/$($SPList.RootFolder.Url)"
        }
        
      }
      IterateWebs($spweb)
      
      }
     }
    }
    IterateWebs($stringweburl)

    how do i do that

    thanks

    Friday, January 27, 2017 5:31 PM

All replies

  • Hi,

    Try using $SPList.Author.UserLogin -ne "SHAREPOINT\System"

    Catalog and Master Page Libraries have 'SHAREPOINT\System' as their Author where as other document libraries wont have it.

    Also in your script you are calling $List.Hidden whereas you have set $SPList as the list variable.

    Try this code,

                

    [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) > $null

    $SiteCollectionUrl = Read-Host "Enter a Site Collection Url: ";
    $site = new-object Microsoft.SharePoint.SPSite($SiteCollectionUrl);

    Write-Host $site.Url

    $stringweburl = $site
    function IterateWebs($stringweburl)
    {

    $w = $stringweburl;

    if($w.AllWebs.Count -gt 0)
    {

    foreach ($SPWeb in $w.AllWebs){

    Write-Host "Subsite  $($SPWeb.Url)"

        foreach($SPList in $SPweb.lists){

        if(($SPList.BaseType -eq "DocumentLibrary") -and ($SPList.Hidden -ne "True") )
        #if($SPList.BaseType -eq "DocumentLibrary")
        {

          Write-Host "DocumentLibrary $($SPWeb.Url)/$($SPList.RootFolder.Url)"
        }
        elseif(($SPList.BaseType -ne "DocumentLibrary") -and ($SPList.Hidden -ne "True") )
        #elseif($SPList.BaseType -ne "DocumentLibrary")
        {
            Write-Host "List $($SPWeb.Url)/$($SPList.RootFolder.Url)"
        }

      }
      IterateWebs($spweb)

      }
     }
    }
    IterateWebs($stringweburl)

    -Rajan

    ---------------------------------------------------------------------------------------------------------

    Please make it as answer if it resolved your issue



    Saturday, January 28, 2017 9:33 AM