Find Most Active SharePoint Sites of a Web Application

Requirement is fairly straightforward. Get me the list of SharePoint sites which are most active (Where updates made quite often)

PowerShell? Yes. Lets get the SPWeb’s Last Item Modified Date and log it to a CSV file to generate the most active sites report.

#Set-ExecutionPolicy RemoteSigned
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$url="https://sharePoint.company.com"
$site = New-Object Microsoft.SharePoint.SPSite($url)
$spWebApp = $site.WebApplication

$OutputFN = "c:\ActiveSitesReport.csv"
"Site Name `t URL `t Last Modified" > $OutputFN

# Iterate through all sites:
 foreach ( $spSite in $spWebApp.Sites )
  {
         foreach ($spWeb in $spSite.AllWebs)
        {
                  if ($spWeb.IsRootWeb)
                  {
                    $siteName = $spWeb.Title +" - Root";
                  }
                  else
                  {
                  $siteName = $spSite.RootWeb.Title + " - " + $spWeb.Title;
                  }                           

              $siteName + "`t" + $spWeb.Url + "`t" + $spWeb.LastItemModifiedDate >> $OutputFN
             $spWeb.Dispose() 
        }
    $spSite.Dispose() 
}

And the .CSV Report file output:

Most Active SharePoint Sites Report

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

8 thoughts on “Find Most Active SharePoint Sites of a Web Application

  • Hi Sal,
    Can you post the completed script to show Pages library as I am unsure how to do that with the code given?

    Can we also output Author and date created?
    Thanks
    Cliff

    Reply
  • Hi Sal,

    – How can I change the script to show the Last Modified date in UK Format i.e. dd/mm/yyyy and NOT American format?

    – How to change the script to also show PAGES within the site?

    Thanks
    Cliff

    Reply
    • – Just replace “$spWeb.LastItemModifiedDate” with “$spWeb.LastItemModifiedDate.ToString(“dd/MM/yyyy”)

      – This script retrieves “Last Modified Date” is a property of SPWeb Object. SPList also has the similar property, so you can get : $SPList.LastItemModifiedDate

      So, to get Pages library, use:

      foreach($web in $site.AllWebs)
      {
      if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web))
      {
      $pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
      $pages = $pubWeb.PagesList
      }
      }

      Reply
  • Hi,

    For some reason it doesn’t work to an extent, it creates the CSV but there is only about 5 sites that it brings through but i have more than 1000 sites in this particular Web Application. Any thoughts as too why this would be happening ?

    Thanks
    Chris

    Reply
    • Chris,

      Do you have Site locks applied on Any of the Site collections? That may be blocking the code from running. Make sure you are running this code in the context of Farm Admin to avoid any access related issues.

      Not getting any other clues as this code is pretty simple!

      Reply
  • Great post. One minor bug in the script:

    “Site Name `t URL `t Last Modified” > $OutputFN

    Should be

    “Site Name `t URL `t Last Modified” > $OutputFile

    or else the header won’t show up in the CSV

    Reply
    • Ahh.. Fixed! Thanks for catching it.

      Reply

Leave a Reply

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