Sunday, January 19, 2014

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!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

1 comment :

  1. i tried this script on sharepoint 2013...but it is not working


Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...