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="http://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 is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

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

  • April 7, 2014 at 3:53 PM

    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
  • March 13, 2014 at 12:25 PM

    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
    • March 13, 2014 at 12:39 PM

      – 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
  • June 12, 2012 at 9:35 AM

    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
    • June 12, 2012 at 12:55 PM

      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
  • May 3, 2012 at 5:48 PM

    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
    • May 3, 2012 at 7:35 PM

      Ahh.. Fixed! Thanks for catching it.

      Reply

Leave a Reply