Hi Guys, I’m having a bit of trouble trying to get the output that I want.
I’ve created a function that does an API call and I am trying to gets its results in a format where I get the field name and field value in a table (like what you see when you do get-process (Name on left, Value on the right)
Below is the section on my script that is putting all the results into a var for me.
end{$Result=""|Select-Object-Property JSONresult, StatusCode, Status, Message, FieldNames, FieldValues, Test$Result.JSONresult=$JSONresult$Result.StatusCode=$JSONresult.API.response.operation.result.statuscode$Result.Status=$JSONresult.API.response.operation.result.status$Result.Message=$JSONresult.API.response.operation.result.Message$Result.FieldNames=$JSONresult.api.response.operation.details.'field-names'.name.content$Result.FieldValues=$JSONresult.api.response.operation.Details.'field-values'.record.value$Result.Test=@{Field=$JSONresult.api.response.operation.details.'field-names'.name.content;Answer=$JSONresult.api.response.operation.Details.'field-values'.record.value}return$Result}
$Result.FieldNames, $Result.FieldValues both give me the required content, but as the API is returning results in a different order each time, I want to match up the field name with the value when the result is collected.
The closest I can get is this
$Result.Test=@{Field=$JSONresult.api.response.operation.details.'field-names'.name.content;Answer=$JSONresult.api.response.operation.Details.'field-values'.record.value}
But that gives me this…
Name Value ---- ----- Field {CI Name, Model, Service Tag, Last Seen on Site} Answer {computername.domain.local, Surface Book, 16264754655157, AU-NSW}
What i want to see is something like this
Name Value ---- ----- CI Name computername.domain.local Model Surface Book
So if i do something like this
$Var = Run-Function -params etc
I can get the info like this.
$var.StatusCode
and can loop through results etc
Foreach($a in $Var.Test) { $a.name (do something) $a.value (do something) }
Can someone please help?
Also, does anyone else have problems with this site? I can’t see my replies and edits, and when I try and reply\save again it says that I have already posted that content. If I modify my reply (just so it doesn’t match) it says that it’s uploaded, but, again I can’t see the replies (I don’t think anyone else can either). I was hoping the last update would have fixed it but I still get these problems.