Good day,
I am neither a seasoned VBScript of PS scripting specialist. My monitoring system has a controlling VBScript for opening support tickets, and it now needs to change to accommodate JSON output posted to a service.
I first attempted to POST the JSON string directly from within the VBScript, but I always get an error “msxml3.dll: A connection with the server could not be established” that I cannot seem to fix. So, I tested the JSON POST from PS, and it worked straight away.
In my infinite wisdom, I then decided to call the PS script from within the VBScript, but that has opened it’s own can of worms. The two biggest worms I’m referring to here are 1) trying to get the call right, and 2) dealing with quotes.
This is the PS call from within my VBS…
strOut = “{“”integrationName””:””WhatsUpGold””,””actionName””:””WhatsUpGold””,””sourceId””:””” & LogID & “””,””payload””:{“”UID””:””” & LogID & “””,””MD””:””SPNVMSA116″”,””Agent_Class””:””WhatsUp Gold””,””Agent_Instance””:””” & mon_name & “””,””Client””:””BCX””,””Date””:””” & ActMonStartTimeDate & “””,””Time””:””” & ActMonStartTimeTime & “””,””ESMTool””:””WhatsUp Gold””,””Severity””:””” & state & “””,””State””:””” & mon_state_override & “””,””Server””:””” & disp_name & “””,””Instance_Detail””:””Server””,””UserData””:””” & payload & “””}}”
Context.LogMessage mon_state & ” ” & disp_name & ” -ACTIVE ” & mon_name & ” monitor alert: ” & strOut
Dim objShell, intReturnCode
Set objShell = CreateObject(“Wscript.Shell”)
intReturnCode = objShell.Run(“powershell.exe -noexit set-ExecutionPolicy Unrestricted -c .c:SXISXI_post_active3.ps1 ” & strOut)
MsgBox intReturnCode
This is my PS script…
$content = $args[0]
[hashtable]$headers=@{}
$headers.Add(“Authorization”, “Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”)
$headers.Add(‘Content-Type’, ‘application/json’)
$headers.Add(‘Accept’, ‘application/json’)
$uri = “https://mywebservice”
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
Invoke-RestMethod -Method ‘POST’ -Uri $uri -Headers $headers -Body $content
The variable strOut in my VBScript passes JSON test, so I thought I would be good to go.
But when I execute my VBS I get the following error from teh PS script output…
At line:1 char:95
- … c .c:SXISXI_post_active3.ps1 {integrationName:WhatsUpGold,actionNa …
-
~
Missing argument in parameter list.
At line:1 char:156
- … actionName:WhatsUpGold,sourceId:4904575,payload:{UID:4904575,MD:SPNVM …
-
~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingArgument
As can be seen, the JSON was good in my VBSCript output, but PS has stripped out the quotes. I think I’ve come to the end of my tether.
I’m also not sure whether I’ve called the PS script correctly from within my VBScript.
Any pointers would be helpful.
Graham Van der vaart is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.