I'm using powershell to get a usage report of a Microsoft Azure environment.
To define the start and end times I use the following:
$reportedStartTime = (Get-Date -day 1 -hour 0 -minute 0 -second 0)
$reportedEndTime = (Get-Date -hour 0 -minute 0 -second 0)
IF($reportedEndTime -eq $reportedStartTime)
{
$reportedStartTime = ($reportedStartTime).AddMonths(-1)
}
Then I run:
Get-UsageAggregates -ReportedStartTime $reportedStartTime -ReportedEndTime $reportedEndTime
But I get the following error:
Get-UsageAggregates :
InvalidInput: The reportedstarttime for daily aggregation granularity
must have the time set to midnight (0:00:00Z).
However, if I call the variable $reportedStartTime
and just copy paste the output:
Get-UsageAggregates -ReportedStartTime "01 September 2016 00:00:00" -ReportedEndTime "01 October 2016 00:00:00"
It works...
What is going on here?
According to your description, I think we can use this script to get the usage report:
Here is my result:
The usage report
If you still have questions, welcome to post back here. Thanks.
Internally the .net DateTime type has a "Kind" property that is set to the time zone you are in when creating the DateTime. You need this "Kind" to be UTC.
In .net I do like this DateTime.UtcNow.Date to get UTC today.
(Yes I know the question is powershell - I am just explaining why I think it fails - then a powershell savvy person can say how to accomplish this in powershell )