Sunday, March 25, 2012

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



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


Check out these SharePoint products:

7 comments :

  1. 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

    ReplyDelete
  2. 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

    ReplyDelete
    Replies
    1. 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!

      Delete
  3. 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

    ReplyDelete
    Replies
    1. - 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
      }
      }

      Delete
  4. 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

    ReplyDelete

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...