Script to verify web service (PowerShell)

Introduction

This script is used verify if the web service is running.

Scenarios

Sometimes, IT admin want to know the web service is running or not. This script is to accomplish it.

Script

This script contains one  advanced function, Test-OSCWebService .You can use this script in the following ways:
1.    Rename scriptname.ps1 to scriptname.psm1 (PowerShell Module file)
2.    Run Import-Module cmdlet to import this module file.
        Import-Module filepath\scriptname.psm1 
 
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
PowerShell
Edit|Remove
$request = [Net.HttpWebRequest]::Create($SiteURL)  
$request.Credentials = $Credentials#Try to get the response from the specified site.If some errors occur, it means the service does not run or you don't have the Credentialtry 
{     
    #Get the response from the requst$response = [Net.HttpWebResponse]$request.GetResponse() 
    Write-Host "The service is running."$request.Abort() 
}     
Catch  
{ 
    Write-Warning"The service of site does not run or maybe you don't have the Credential" 
}

Examples

Example 1: Get help about  Test-OSCWebService
Command:   Get-Help Test-OSCWebService -Full
Screenshot:
Example 2: Test the web service of specified site with default credential
Command:   Test-OSCWebService -SiteURL "http://www.microsoft.com"
Screenshot:
Note:  The value of  “SiteURL” must include “http://”.
Example 3: Test the web service of specified site with specified credential
Command:   Test-OSCWebService -SiteURL "http://www.microsoft.com"
Screenshot:

Prerequisite

Windows PowerShell 2.0

Additional Resources

Related Forum Threads:
How do I verify if web services is enabled 
Powershell-how to execute http post to verify web service is running