SharePoint Site Collections and Subsites Inventory Report

Requirement: Get a list of all site collections and their subsites in an HTML formatted report!

PowerShell Script to generate an HTML report for Site Collections & Subsites:

Are you looking for a way to generate an inventory report of all your SharePoint site collections and subsites? In this blog post, I will show you how to use the PowerShell script to generate a report of all sites in your SharePoint environment. This report is helpful for quickly creating a detailed inventory of all your SharePoint sites.

#Add SharePoint Snapin
if ( (Get-PSSnapin -Name "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null ) {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"

# Configuration Variables
$WebApplicationURL = ""
$ReportOutput = "C:\SiteCollectionsAndSites.html"

#Get all Site Collections from the webapplication
$SitesColl= Get-SPWebApplication $WebApplicationURL | Get-SPSite -Limit All

<!-- Sal - Javascript Function to apply formatting -->
<script type="text/javascript">
function altRows(id){
  var table = document.getElementById(id);  
  var rows = table.getElementsByTagName("tr");     
  for(i = 0; i < rows.length; i++){          
   if(i % 2 == 0){
    rows[i].className = "evenrowcolor";
    rows[i].className = "oddrowcolor";
<!-- CSS Styles for Table TH, TR and TD -->
<style type="text/css">
body{ font-family: Calibri; height: 12pt; }
table.altrowstable {
 border-collapse: collapse; font-family: verdana,arial,sans-serif;
 font-size:11px; color:#333333; border-width: 1px; border-color: #a9c6c9;
 border: b1a0c7 0.5pt solid; /*Sal Table format */  
table.altrowstable th {
 border-width: 1px; padding: 5px; background-color:#8064a2;
 border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt; 
 color: white;  font-size: 11pt;  font-weight: 700;  text-decoration: none;
table.altrowstable td {
 border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt; color: black; 
 font-size: 11pt; font-weight: 400; text-decoration: none; 
.oddrowcolor{ background-color: #e4dfec; }
.evenrowcolor{ background-color:#FFFFFF; }

 #Add the HTML File with CSS into the Output report
$Content = $HTMLTemplate > $ReportOutput
"<h2> Site Collections & Subsites Report </h2>" >> $ReportOutput  
#Table of Contents
"<h3> Summary of Site Collections</h3> <table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr><th>Site Collection Name </th><th> URL </th><th> No.Of Subsites </th></tr>" >> $ReportOutput

#Loop throuh each site collection 
foreach($Site in $SitesColl) 
    "<tr> <td> <a href='#$($Site.Rootweb.Title.ToLower())'>$($Site.Rootweb.Title)</a> </td><td> $($Site.Rootweb.URL)</td> <td> $($Site.AllWebs.Count) </td></tr>" >> $ReportOutput
"</table><br/><hr>" >> $ReportOutput

#Get All sub Sites
foreach($Site in $SitesColl) 
    "<h4> Subsites of Site Collection: <a name='$($Site.RootWeb.Title.ToLower())' href='$($Site.RootWeb.URL)' target='_blank'>$($Site.RootWeb.Title)</a> </h4> ">> $ReportOutput
    "<table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr><th>Site Name </th><th> Site URL </th><th> Last Modified </th></tr>" >> $ReportOutput
    foreach($Web in $Site.AllWebs)
      "<tr> <td>$($web.Title)</td><td> <a href='$($web.URL)' target='_blank'>$($web.URL)</a></td> <td> $($web.lastitemmodifieddate) </td></tr>" >> $ReportOutput
    "</table></br> " >>$ReportOutput
} #Web
"</body></html>" >>$ReportOutput

Write-host "`n Site Collections & Subsites Report generated successfully at "$ReportOutput

Report Output:

SharePoint Site Collections and Subsites Inventory Report

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

6 thoughts on “SharePoint Site Collections and Subsites Inventory Report

Leave a Reply

Your email address will not be published. Required fields are marked *