Smart Way Of Extracting The Overall Folder Structure Inventory Report On A Document Library

Let's  explore a cool and amazing way to extract the whole overall document library's nested folder structure, its respective documents and their respective file sizes in a CSV report using PnP PowerShell.
 
Here is the cool script for generating the above folder structure and related information in a fraction of a second:
  1. #Connect to SPO  
  2. Connect - PnPOnline - Url "https://samplesharenet.sharepoint.com/sites/classictest"  
  3. #My list target  
  4. $myList = "/FlowCopyTestLib"  
  5. #Store the results  
  6. $results = @()  
  7. foreach($list in $myList) {  
  8.     $allItems = Get - PnPListItem - List $list - Fields "FileLeafRef""SMTotalFileStreamSize""FileDirRef""FolderChildCount""ItemChildCount"  
  9.     foreach($item in $allItems) {  
  10.         #Narrow down to folder type only  
  11.         if (($item.FileSystemObjectType) - eq "Folder") {  
  12.             $results += New - Object psobject - Property @ {  
  13.                 FileType = $item.FileSystemObjectType  
  14.                 RootFolder = $item["FileDirRef"]  
  15.                 LibraryName = $list  
  16.                 FolderName = $item["FileLeafRef"]  
  17.                 FullPath = $item["FileRef"]  
  18.                 FolderSizeInMB = ($item["SMTotalFileStreamSize"] / 1 MB).ToString("N")  
  19.                 NbOfNestedFolders = $item["FolderChildCount"]  
  20.                 NbOfFiles = $item["ItemChildCount"]  
  21.             }  
  22.         }  
  23.     }  
  24. }  
  25. #Export the results  
  26. $results | Export - Csv - Path "D:\NestedFoldersForONEdoclib.csv" - NoTypeInformation  
Just update your details in the above highlighted area and run the script on a Windows PowerShell ISE.
 
You will receive a cool CSV report generated with all the details in the mentioned path, say D:\ folder for my script as mentioned.
 
The CSV Report should contain all the below columns:LibraryName
  • NbOfNestedFolders
  • FolderSizeInMB
  • NbOfFiles
  • FullPath
  • RootFolder
  • FolderName
  • FileType 
You need to enter your log in details but make sure they are some Site Admin/Global Admin Details.
 
Note
The above script is only supported on SP Online Environment.
 
There is one more OOTB method by simply visiting the ink:- https://<TenantName>.sharepoint.com/sites/<SiteName>/_layouts/15/storman.aspx?root=<LibraryName> . Here you can also check individual files/documents size occupied which are not in any of the Nested Folders. This can be used further for your analysis. 
 
Cheers!