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. # Add SharePoint PowerShell Snapin
  4. if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
  5. Add-PSSnapin Microsoft.SharePoint.Powershell
  6. }
  7. $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
  8. Set-Location $scriptBase
  9. #Deleting any .rtf files in the scriptbase location
  10. $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
  11. if($FindRTFFile)
  12. {
  13. foreach($file in $FindRTFFile)
  14. {
  15. remove-item $file
  16. }
  17. }
  18. start-transcript $logfile
  19. function GetSPHealthScore {
  20. param(
  21. [Parameter(ValueFromPipeline=$true)]
  22. [string] $url
  23. )
  24. $request = [System.Net.WebRequest]::Create( $url )
  25. $request.Credentials = [System.Net.CredentialCache]::DefaultCredentials
  26. $headers = $request.GetResponse().Headers
  27. $headers.AllKeys |
  28. Select-Object @{ Name = "Key"; Expression = { $_ }},
  29. @{ Name = "Value"; Expression = { $headers.GetValues( $_ ) } }
  30. }
  31. $SiteCollectionURL = read-host "enter the site collection url"
  32. GetSPHealthScore $SiteCollectionURL