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
- $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
- $LogFile = ".\GetSPHealthScorePatch-$LogTime.rtf"
-
- # Add SharePoint PowerShell Snapin
-
-
- if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
- Add-PSSnapin Microsoft.SharePoint.Powershell
- }
-
- $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
- Set-Location $scriptBase
-
-
- #Deleting any .rtf files in the scriptbase location
- $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
- if($FindRTFFile)
- {
- foreach($file in $FindRTFFile)
- {
- remove-item $file
- }
- }
-
- start-transcript $logfile
-
- function GetSPHealthScore {
- param(
- [Parameter(ValueFromPipeline=$true)]
- [string] $url
- )
-
- $request = [System.Net.WebRequest]::Create( $url )
- $request.Credentials = [System.Net.CredentialCache]::DefaultCredentials
-
- $headers = $request.GetResponse().Headers
-
- $headers.AllKeys |
- Select-Object @{ Name = "Key"; Expression = { $_ }},
- @{ Name = "Value"; Expression = { $headers.GetValues( $_ ) } }
-
- }
-
- $SiteCollectionURL = read-host "enter the site collection url"
- GetSPHealthScore $SiteCollectionURL