SharePoint 2013 Site Response Time- Home Page - PowerShell


I wanted to Verify the response time of the all home pages of my Entire Farm using PowerShell Script.

with little bit of Google I was able to find out all the required components for me to come up with the Response time of the Each site home page for entire Farm

few of the key sections which I was looking in google were Response time

$TimeResponse = Measure-Command -Expression {
                    $Response = invoke-webrequest -Uri $web.Url -UseDefaultCredential ;

Basic Logic of the Script is based on Response code (200 for success) I'm writing in to a text file about the time taken to response from web site home page.

Entire Script came up as follows including Logs

Add-PSSnapin Microsoft.SharePoint.PowerShell

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

cls;

$timeStamp = Get-Date;
$startTime = $timeStamp.ToString("yyyy-MM-dd-HH-mm:s");
$ExecutionID = $timeStamp.ToString("yyyyMMddHHmm"); 

Write-Host $startTime

 $logFilePath = "… \$ExecutionID-SiteAvailability.log";

Add-Content -Path $logFilePath -value "WebApplication | SiteCollection |FirstLevelSubSite | StatusCode | Status Description | Response Time |Exception | Created |Last modified";

 function ValidateSites()
{

    $allSiteCollections = Get-SPSite -Limit All

    $Response = $null ;
    $error = "";
    $siteCreated = "";
    $siteModified = "";

    foreach ($sitecollectoin in $allSiteCollections)
    {
        $siteCollURL = $sitecollectoin.URL;
         $allTopWebs = $sitecollectoin.AllWebs;

        foreach ($web in $allTopWebs)
        {  
            TRY {

                $TimeResponse = Measure-Command -Expression {
                    $Response = invoke-webrequest -Uri $web.Url -UseDefaultCredential ;

                }
                IF ($Response.StatusCode -eq "200")
                {
                    Write-Host "URL: " $web.Url " -Status:" $Response.StatusCode " Response Time (ms): "$TimeResponse -f Green;
                }
                ELSE
                {              
                    Write-Host "URL: " $web.Url " -Status:" $Response.StatusCode " Response Time (ms): "$TimeResponse -f Red;

                }

                $siteCreated = $web.Created;
                $siteModified = $web.LastItemModifiedDate;
               
            }
            CATCH [Exception]
            {
                write-host -f red $_.Exception.ToString() ;
                $error = $_.Exception.ToString();
            }
            FINALLY
            {
                 Add-Content -Path $logFilePath -value "$($sitecollectoin.WebApplication.Url) | $($siteCollURL) |$($web.Url) | $($Response.StatusCode) | $($Response.StatusDescription) |$($TimeResponse)| $($error) |$($siteCreated) | $($siteModified)";

                $Response = $null;
                $error = "";
                $web.Dispose()

            }
        }

         $web.Dispose()

     }

}

#Calling the Method written in above section to execute and get each site 
#response time
ValidateSites;


$timeStamp = Get-Date;
$endTime = $timeStamp.ToString("yyyy-MM-dd-HH-mm:s");


Write-Host $startTime;
Write-Host $endTime;


Popular posts from this blog

How to Create Host Header to SharePoint Web Application

System.Data.SqlClient.SqlException (0x80131904): The EXECUTE permission - User Profile Issue

How to add PDF Icon in SharePoint