Retrieving Azure Monitor metrics

Hello everyone,

Im trying to retrieve metrics from Azure monitor API, however I have to define a start and endtime when retrieving a specific metric, but I’m struggling to create a start and endtime with the correct format with powershell. Ideally I want to retrieve the last metric value available.

I’m using this as a reference but the API documentation is very limited unfortunately.

https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-rest-api-walkthrough

Here’s the filter that the reference documentation is talking about.

Here I simply want start and endtime to be generated by powershell with a get-date or something similar, but I’m unsure how to construct this.

$filter = “(name.value eq ‘RunsSucceeded’) and aggregationType eq ‘Total’ and startTime eq 2017-08-18T19:00:00 and endTime eq 2017-08-18T23:00:00 and timeGrain eq duration’PT1H’”

Any ideas how to get startTime and endTime generated in powershell so it only shows the last result? Would like to use these values to extend them as performance rules into SCOM.

Br,
Jasper

Consider my question as resolved. I asked it in the documents section of the Azure monitor API and it was answered. To generate the dates its

$start = (Get-Date)
$end = $start.AddMinutes(5)
$startTime = $start.ToString("s")
$endTime = $end.ToString("s")

Br,
Jasper

https://docs.microsoft.com/en-us/rest/api/monitor/filter-syntax

is there a missing character from the time format i.e.

$filter = “(name.value eq ‘RunsSucceeded’) and aggregationType eq ‘Total’ and startTime eq 2017-08-18T19:00:00Z and endTime eq 2017-08-18T23:00:00Z and timeGrain eq duration’PT1H’”

date format missing a Z (guessing for Zulu Time) at the end?