I had a similar issue, where the execution should be trigger by an external scheduler. Let's assume that
- The usage of a script, in a secured folder, is permitted (where the exit code is expected by the scheduler)
- The usage of a script permits the access to a sensitive information (and this is why is preferred to have it in a secured folder
you can set up a powershell like I did in the following way:
##################### START Settings #####################
[System.String] $soap_url = "
https://soap:8443/webservicemethod"
[System.String] $soap_userid = "username"
[System.String] $soap_password = "password"
##################### END Settings #####################
[System.String] $soap_credential_base64 = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $soap_userid, $soap_password)))
try {
# Preparing the request
$soap_web_request = [System.Net.WebRequest]::Create($soap_url)
$soap_web_request.Headers.Add("Authorization", "Basic $soap_credential_base64")
$soap_web_request.Headers.Add("SOAPAction", "soap method")
$soap_web_request.ContentType = "text/xml;charset=UTF-8"
$soap_web_request.Accept = "text/xml"
$soap_web_request.Method = "POST"
$soap_web_request_stream = $soap_web_request.GetRequestStream()
$soap_request_message.Save($soap_web_request_stream)
$soap_web_request_stream.Close()
$soap_web_response = $soap_web_request.GetResponse()
$soap_web_response_stream = [System.IO.StreamReader] $soap_web_response.GetResponseStream()
$soap_response_message = [System.Xml.XmlDocument] $soap_web_response_stream.ReadToEnd()
$soap_web_response_stream.Close()
# Parsing the SOAP response and lookup for the XmlNode interested value
[System.Xml.XmlNamespaceManager] $soap_response_namespace_manager = $soap_response_message.NameTable
$soap_response_namespace_manager.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/") $response_info_node = $soap_response_message.SelectSingleNode("xpathexpression", $soap_response_namespace_manager)
exit 0
} catch [System.Management.Automation.MethodInvocationException] {
$method_invocation_error_message = $_.Exception.Message
Write-Host "[MethodInvocationException] $method_invocation_error_message" -Foreground "red"
exit 1
}