According to the documentation, I should enclose both values within square brackets, but this doesn't seem to work.
My code is as follows :
$params = @{
body = @{
"jsonrpc"= "2.0"
"method"= "item.get"
"params"= @{
"host"= $HostName
"search"= @{
"key_"= "[vm.memory.size[total],system.cpu.num]"
}
"searchByAny"= "true"
}
"id"= 50
"auth"="e57c8231e4d8f0f1c8d3ea2209299e65864a8c394458f670a9bc35583c19e129"
} | ConvertTo-Json
uri = "$baseurl/api_jsonrpc.php"
headers = @{"Content-Type" = "application/json"}
method = "Post"
}
$HostDetails = $($_.HostName)
$result = Invoke-WebRequest @params -useBasicParsing
$rawdata = $result | ConvertFrom-Json
#$rawdata.result
but it doesn't work, it produces the following result -
StatusCode : 200
StatusDescription : OK
Content : {"jsonrpc":"2.0","result":[],"id":50}
RawContent : HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Strict-Transport-Security: max-age=315360...
Forms :
Headers : {[Access-Control-Allow-Origin, *], [Access-Control-Allow-Headers, Content-Type], [Access-Control-Allow-Methods,
POST], [Access-Control-Max-Age, 1000]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml :
RawContentLength : 37
I tried changing the line "key_" = .... to all sorts of variants of what I have above but nothing seemed to produce any results, some threw errors.
According to the documentation, I should enclose both values within square brackets
I highly doubt that - the documentation probably states you need to supply an array of keys, which in JSON would be [ "<key1>", "<key2>", ... ]
.
In PowerShell, you'll want to use the array subexpression operator:
@{
"key_" = @('vm.memory.size[total]', 'system.cpu.num')
}
Once converted to JSON, it will eventually look like "key_":["vm.memory.size[total]", "system.cpu.name"]