Here's a chunk of code for tokenizing the raw data returned from the REST API into something easier to use in powershell for processing / report generation. $response is the return from the invoke-restmethod call:
Now we can access an individual data point with $dataCounters.datasourcename... in my case, I was getting RAM info for a VM: $dataCounters.freePhsyicalMemory gets me an array of dictionaries that I can loop through:
Question
Cole McDonald 14
Here's a chunk of code for tokenizing the raw data returned from the REST API into something easier to use in powershell for processing / report generation. $response is the return from the invoke-restmethod call:
<# Objectify Data Points #> $dataCounters = @{} $index = 0 $dataPoints = $response.data.dataPoints.Count while ( $index -lt $response.data.time.count ) { $time = $response.data.time[$index] $value = $response.data.values[$index] $dataPointCounter = 0 while ( $dataPointCounter -lt $dataPoints ) { $dataCounters[$response.data.dataPoints[$dataPointCounter]] += @(@{ "time" = $time "value" = $value[$dataPointCounter] }) $dataPointCounter++ } $index++ }
Now we can access an individual data point with $dataCounters.datasourcename... in my case, I was getting RAM info for a VM: $dataCounters.freePhsyicalMemory gets me an array of dictionaries that I can loop through:
foreach ( $counter in $dataCounters.freePhsyicalMemory ) { write-output "$($counter.time) - $($counter.value)" }
Or filter with $dataCounters.freePhsyicalMemory | where time -gt 1553695107000
I can still access the full list of values or times via $dataCounters.freePhysicalMemory.Value or $dataCounters.freePhysicalMemory.Time
<Moderators: feel free to move this elsewhere. I don't have access to the tips/tricks part of the board>
Link to post
Share on other sites
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.