Testing Webapps On Each SharePoint Server

I love single line PowerShell commands. Scripts can be boring, but it you can condense everything down to a single line, you sir, rock.

If you’re running a multi-server farm and using a load-balancer to handle getting the web requests to a Front End servers, you’ll sometimes (always) really like to know if the webapps are responding correctly on each server. If you’re like me, you place self-referencing host file entries on each server for each Web Application. No sense in having the servers send WFE request back to the load-balancer. And, magically, that’s a pre-requisite for this PowerShell command running. Without the host file entries on each server, the web requests will just go to the load-balancer, and you’ll never figure out who’s working and who’s not.

Log on to each of your SharePoint servers and fire up the handy-dandy SharePoint Management Console. Once you’re there, fire off this command:

Clear-Host;Get-SPWebApplication | Select -expand URL | %{$wa= $_;$request = [System.Net.WebRequest]::Create($_);$request.Timeout = 30000;$request.UseDefaultCredentials = $true;Try{$webcall = ($request.GetResponse());Write-Host "Site:$($webcall.ResponseUri) -- StatusCode $($webcall.StatusCode)";Write-Host "`r"} Catch [system.exception] {Write-Host "$wa Failed -- $($error[0].Exception.Message)";Write-Host "`r"}}

This will pull each URL from SharePoint and spin up a web request and show you the feedback.

Note: You may need to adjust the timeout variable in the web request if your app pools have spun down and they need longer than 30 seconds to come back up.

Hope it helps!

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation