0

I need to run a report for my client that will list the whole site structure in a site collection - subsites, libraries and folders + sub folders - no need to list the files/document inside, I only need the structure. How can I get something like that? I use Sharepoint 2016 on premises

1

try the following script:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function GetSubFolders($Folder)
{ 
   Write-Host "+"$Folder.Name


   #Loop through all subfolders and call the function recursively
     foreach ($SubFolder in $Folder.SubFolders)
        {
        if($SubFolder.Name -ne "Forms")
        {  
          Write-Host "`t" -NoNewline
        GetSubFolders($Subfolder)

      }
    }
 }

#Get the Site collection 
$Site= Get-SPSite "http://sharepoint.com" 
       #Loop throuh all Sub Sites
       foreach($Web in $Site.AllWebs)
       {
      Write-Host "-----------------------------------------------------"
      Write-Host "Site Name: '$($web.Title)' at $($web.URL)"
    Write-Host "-----------------------------------------------------"
      foreach($list in $Web.Lists)
    {
       #Filter Doc Libs, Eliminate Hidden ones
      if(($List.BaseType -eq "DocumentLibrary") -and ($List.Hidden -eq $false) )
               { 
          GetSubFolders($List.RootFolder)
         }
    }
     }
  • Thank you Max576, the script gave me what I needed. Much appreciated – Heste Apr 19 '18 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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