Test webservices with Powershell

I use this little thing to test webservices (by invoking SOAP/GET request etc) whenever I want to parse the output to, say, Windows Event Logs, or the nearest SoapUI installation is far far away.
The $request.SetRequestHeader parameters may vary from situation to situation, but in most cases this code should be sufficient for simple Webservices.
The only thing you need is the Webservice URL, and a set of XML parameters, depending on which test you want to do.

Originally written as a function for a bigger script, but the code should be easy to modify for other stuff.

#-- Global Parameters

$global:WebServiceURL = " -- URL to webservice here -- "
$global:XMLParameters = @"

-- Paste you XML request here --


#-- The Actual Function

function CallWebservice {
echo "Sending webrequest to $WebServiceURL"

$request = New-Object -ComObject Msxml2.XMLHTTP
$request.open('POST', $WebServiceURL, $false)
$request.setRequestHeader("Content-type", "text/xml; charset=utf-8")
$request.setRequestHeader("Content-length", $XMLParameters.length)
$request.setRequestHeader("Connection", "close")


– F