hi I have a very simple script trying to read json input, and convert
param(
$proxyinfosjson
)
write-output "proxyinfosjson is $proxyinfosjson"
try {
$proxyinfos = ConvertFrom-Json -InputObject $proxyinfosjson
write-output $proxyinfos
}
catch {
Write-Output "could not convert json input"
}
if I run
.\testjson.ps1 -proxyinfosjson '[{"listenport":"443","connectaddress":"10.1.10.20","connectport":"443","firewallrulename":"port443","direction":"Inbound","action":"Allow","protocol":"TCP"},{"listenport":"80","connectaddress":"10.1.10.20","connectport":"80","firewallrulename":"port80","direction":"Inbound","action":"Allow","protocol":"TCP"}]'
it works fine, I can see the json input is showing as
proxyinfosjson is [{"listenport":"443","connectaddress":"10.1.10.20","connectport":"443","firewallrulename":"port443","direction":"Inbound","action":"Allow","protocol":"TCP"},{"listenport":"80","connectaddress":"10.1.10.20","connectport":"80","firewallrulename":"port80","direction":"Inbound","action":"Allow","protocol":"TCP"}]
however, if I run
powershell -ExecutionPolicy Unrestricted -file testjson.ps1 -proxyinfosjson '[{"listenport":"443","connectaddress":"10.1.10.20","connectport":"443","firewallrulename":"port443","direction":"Inbound","action":"Allow","protocol":"TCP"},{"listenport":"80","connectaddress":"10.1.10.20","connectport":"80","firewallrulename":"port80","direction":"Inbound","action":"Allow","protocol":"TCP"}]'
it doesn't work, I can see json input is showing as
proxyinfosjson is [{listenport:443,connectaddress:10.1.10.20,connectport:443,firewallrulename:port443,direction:Inbound,action:Allow,protocol:TCP},{listenport:80,connectaddress:10.1.10.20,connectport:80,firewallrulename:port80,direction:Inbound,action:Allow,protocol:TCP}]
notice how all quotes are missing? as a result of that it couldn't convert from json why?