Powershell Script to Find SharePoint 2010 Server Health Score

PowerShell script to find SharePoint 2010 server health score.
 
The PowerShell script is used to find the health score for SharePoint server. when you make a call to SharePoint, it adds a custom HTTP header to the response that tells you how the server is doing. The score ranges from 0 to 10. Various server statistics are taken into account to calculate this score. Less the number more efficient is the server. 

Script 
  1. $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm  
  2. $LogFile = ".\GetSPHealthScorePatch-$LogTime.rtf"  
  3.  
  4. # Add SharePoint PowerShell Snapin  
  5.   
  6.   
  7. if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {  
  8.     Add-PSSnapin Microsoft.SharePoint.Powershell  
  9. }  
  10.   
  11. $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent  
  12. Set-Location $scriptBase  
  13.  
  14.  
  15. #Deleting any .rtf files in the scriptbase location  
  16. $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf  
  17. if($FindRTFFile)  
  18. {  
  19.  foreach($file in $FindRTFFile)  
  20.   {  
  21.    remove-item $file  
  22.   }  
  23. }  
  24.   
  25. start-transcript $logfile  
  26.   
  27. function GetSPHealthScore {  
  28. param(  
  29.     [Parameter(ValueFromPipeline=$true)]  
  30.     [string] $url  
  31. )  
  32.   
  33. $request = [System.Net.WebRequest]::Create( $url )  
  34. $request.Credentials = [System.Net.CredentialCache]::DefaultCredentials  
  35.   
  36. $headers = $request.GetResponse().Headers  
  37.   
  38. $headers.AllKeys |  
  39. Select-Object @{ Name = "Key"; Expression = { $_ }},  
  40. @{ Name = "Value"; Expression = { $headers.GetValues( $_ ) } }  
  41.           
  42. }  
  43.   
  44. $SiteCollectionURL = read-host "enter the site collection url"  
  45. GetSPHealthScore $SiteCollectionURL  

 

Ebook Download
View all
Learn
View all