Find Top 10 Site Collections based on its Usage during Last Month

PowerShell Script to find top 10 SharePoint 2007 site collections based on its usage hits:


#Functions to Imitate SharePoint 2010 Cmdlets in MOSS 2007
function global:Get-SPWebApplication($WebAppURL)
  return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
function global:Get-SPSite($url) {
    return new-Object Microsoft.SharePoint.SPSite($url)
function global:Get-SPWeb($url) {
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null) {
    return $web

#Get all site collections of the provided web application
$WebApp = Get-SPWebApplication ""
$SitesCollection = $WebApp.Sites

$UsageDataCollection = @()
 #Iterate through each site collection
 ForEach($site in $SitesCollection)
    $web = Get-SPWeb $site.URL
    $LastMonthUsage = ($web.GetUsageData("url", "lastMonth") | sort 'Total Hits')
    If($LastMonthUsage -ne $null)
        $totalHits = ($LastMonthUsage | Measure-Object 'Total Hits' -Sum | Select -expand Sum)     
        $UsageDataResult = New-Object PSObject
        $UsageDataResult | Add-Member -type NoteProperty -name "Site Collection URL" -value $site.URL
        $UsageDataResult | Add-Member -type NoteProperty -name "Site Title" -value $web.title
        $UsageDataResult | Add-Member -type NoteProperty -name "Total Hits" -value $totalHits

        $UsageDataCollection += $UsageDataResult

        #Clear variables
        $LastMonthUsage = $null
        $tHits = $null
 $UsageDataCollection | sort-object "Total Hits" -descending | select-object -first 10 | Export-csv "Top10Sites.csv" -notypeinformation 

For SharePoint 2010 and above, Use Web Analytics Web Part!

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

One thought on “Find Top 10 Site Collections based on its Usage during Last Month

  • i tried this script on sharepoint 2013…but it is not working


Leave a Reply

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