Testing website status

Like any applications, websites require a number of other components, such as the network and the operating system, in order to function. In the case of a problem you need to isolate the component causing the problem. One quick test is to see if the website is running. If you can confirm that it shows that the network and other components
are functioning.
The phone rings. “The website isn’t available,” shouts the user. You need to check whether the website is up before performing other diagnostics.
The following listing enables you to retrieve the website status,

$ws = DATA {
ConvertFrom-StringData -StringData @'
1 = Started
2 = Starting
3 = Stopped
4 = Stopping
5 = Unknown
function get-websitestatus {
param (

if ($site) {
$sites = Get-WmiObject -Namespace 'root\webadministration' -Class Site -ComputerName $computername -Authentication 6 -Filter "Name='$site'"
else {
$sites = Get-WmiObject -Namespace 'root\webadministration' -Class Site -ComputerName $computername -Authentication 6
$data = @()

foreach ($site in $sites){
$wsdata = New-Object -TypeName PSobject
Add-Member -InputObject $wsdata -MemberType NoteProperty -Name "Name" -Value $site.Name

$state = $site.GetState()
Add-Member -InputObject $wsdata -MemberType NoteProperty -Name "Status" -Value $ws["$($state.ReturnValue)"]

$data += $wsdata