VBScript: When You Can’t Use Powershell to Ping a Webpage…

Sometimes, there’s a need to schedule a “ping” to a webpage (that needs to be pre-compiled, for instance). While using PowerShell is the easiest way to do this, it’s not always available on older server, while VBScript is nearly always a safe bet. The biggest issue with using VBScript or the command line is what to do with the window it may open. Instead of using iexplore and taskkill, using the following VBScript is my fav alternative.

Call pingPage ("http://www.domain.com")

Function pingPage (strURL)
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strURL, false

If objXMLHTTP.Status <> 200 Then
'email someone about it
End if

Set objXMLHTTP = Nothing
End Function

On a related note: the PowerShell line looks something like this: $pingPage = (new-object net.webclient).DownloadString(“http://www.domain.com”)

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, and holds a number of certifications, including those relating to SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in PowerShell, VBScript
One comment on “VBScript: When You Can’t Use Powershell to Ping a Webpage…
  1. frankCBA says:

    Havn’t thought about it before..but why not?! thx ;-)

Leave a Reply

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