Powershell script for SharePoint 2010 & SharePoint 2007 Site Usage report

SharePoint 2010 & SharePoint 2007  – Powershell script for finding site Url, Title,user Count, Primary & Secondary Site collection admins, Usage, Hits, views, Created Date, last modifed date

[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
# get local farm
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
# get web services from local farm
$websrvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
# format for .csv file output
$outputToCSV = @()
function CheckedOutItems()
{
    # get all web services available in the farm   
    foreach ($websrvc in $websrvcs) {
        # retrieve web applications
        foreach ($webApp in $websrvc.WebApplications) {
            # now get site collections from the web application
            foreach ($site in $webApp.Sites) {
                # process each web site
                Try {
                    foreach ($web in $site.AllWebs) {
                         $siteUrl = $web.Url
                         $siteName = $web.Title
                         $siteUserCnt = $web.AllUsers.Count
                         $PimarySiteAdmin = $site.Owner.Name
                         $SecondarySiteAdmin = $site.SecondaryContact.Name
                      $siteusage = $site.Usage.Storage/1MB
                         $Hits = $site.Usage.Hits                       
                         $Created = [datetime]$web.Created
                         $LastModified = $Web.LastItemModifiedDate
                         $SnapShot = (get-date)
                         $LastUpdate = ($SnapShot – [datetime]$LastModified)

                         $outputToCSV += New-Object PSObject -Property @{"Site Title" = $siteName; "Url" = $siteUrl; "Primary site collection admin"= $PimarySiteAdmin; 
                                                                        "Secondary site collection admin"=$SecondarySiteAdmin; "Total Users" =$siteUserCnt;"Size" = $siteusage; 
                                                                        "Date Last Modified" = $LastModified; "Days Last Update" = $LastUpdate; "Hits" =$Hits; "Date Created" =$Created
                                                                        }
                                        $file_date = get-date -format M-d-yyyy
                                        $file_name = "$env:USERPROFILE\Desktop\NoCheckedInVersion"+ $file_date + ".csv"
                                        $outputToCSV | ConvertTo-Csv -notype > $file_name

                } # end $site.AllWebs loop
            } # end Try statement 
            # General catch exceptions
            Catch {
                    "General Exceptions caught: " >> "$env:USERPROFILE\Desktop\errorlog.txt"
                    $_.Exception.Message >> "$env:USERPROFILE\Desktop\errorlog.txt"
            }# end general catch statement
            }
        }
    }
}
# Make a call to the function
CheckedOutItems
Advertisements

3 thoughts on “Powershell script for SharePoint 2010 & SharePoint 2007 Site Usage report

  1. Hi, i need to provide a complete report on sharepoint 2007 Farm
    like number of webapplications,owner,created,administrator, site collections,sites, and tell me out to run your code

  2. Hi Rasool,

    PowerShell is a tool that allows us to run scripts or commands on our server. PowerShell is included with Windows Server 2008 or 2008 R2 but not in Windows Server 2003. It is recommended to install PowerShell on all servers. We must be on Windows Server 2003 / 2003 R2 Service Pack 2 (SP2) in order to use PowerShell v2. Find the link below
    http://www.sharepointdiary.com/2011/05/how-to-use-powershell-with-sharepoint-2007.html

    Once Installed you can run my script to get complete report. The output will be CSV file. Find the link to my blog

    Thanks,
    Santosh

  3. Pingback: Powershell script for SharePoint 2010 & SharePoint 2007 Site Usage report – SharePoint | Crashcarr

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s