Rest API format and powershell?

How do you join the two answers so they are properties of one object?

$uri = ‘https://servername:52311/api/query?relevance=(name of it, last report time of it) of bes computers’

$jBody = @{
output = “json”
}

$d = Invoke-RestMethod -Uri $uri -body $jbody -Credential $credentials
$d.result

It’s outputting this.

servera
Wed, 31 Jan 2018 15:41:39 -0500
serverb
Wed, 31 Jan 2018 14:45:07 -0500

I’m not a pro at xml but it seems the format is off. If I look at xml for splunk you have a value for every field and easily outputs to json.

- - - mycomputer - - F:

I’d have to test more specifically with PowerShell, but it must be noted that the default output is XML and not JSON. It may help to modify your URI to optionally output as JSON:

$uri = ‘https://servername:52311/api/query?relevance=(name of it, last report time of it) of bes computers&output=json’

(IBM BigFix 9.1 REST API Serve in JSON?)

1 Like

Thanks for the tip on the &output=json, that’s a bit easier but still results in the same problem. Each result is an array (in this case 2) where I have to loop through the results and form an object. Due to this format it’s simpler just to grab the computers table from sql. Alternatively I could fetch the id from api/computers but I still have to loop through each to get the details. I was wondering if there is a better query.

$uri = 'https://bigfixserver:52311/api/query?relevance=(name of it, license type of it) of bes computers'

$jBody = @{
output = “json”
}

$d = Invoke-RestMethod -Uri $uri -body $jbody -Credential $c

$o = $d.result | %{

[pscustomobject]@{

servername = $[0]
os = $
[1]

}

}

1 Like