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.
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.