Skip to content

Usagesummary.ps1 does not properly handle [DateTime] variants for StartTime/EndTime #609

Open

Description

Issue was reported on stamp version 2005, however the report generates on 2002 stamp properly with the same inputs.

Ask: Validate Usagesummary.ps1 on stamp versions > 2002. I have not tested this yet.

https://github.com/Azure/AzureStack-Tools/blob/master/Usage/Usagesummary.ps1

PS C:\Users\vmadmin\Documents> .\usagesummary.ps1
cmdlet usagesummary.ps1 at command pipeline position 1
Supply values for the following parameters:
StartTime: 2021-05-20
EndTime: 2021-06-01
Get-AzsSubscriberUsage : The reported date time '2021-05-20T00:00:00.0000000 00:00' is not in ISO 8601 format(YYYY-MM-DDTHH:mm:ss.sssZ).
At C:\Users\vmadmin\Documents\usagesummary.ps1:129 char:1
+ $result = Get-AzsSubscriberUsage -ReportedStartTime ("{0:yyyy-MM-ddT0 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ({ SubscriptionI...ationToken =  }:<>f__AnonymousType0`6) [Get-AzsSubscriberUsage_List], UndeclaredResponseException
    + FullyQualifiedErrorId : BadRequest,Microsoft.Azure.PowerShell.Cmdlets.CommerceAdmin.Cmdlets.GetAzsSubscriberUsage_List

Switching line 129 to this and it works:

$result = Get-AzsSubscriberUsage -ReportedStartTime $StartTime  -ReportedEndTime $EndTime -AggregationGranularity $Granularity

Activity

  1. cblackuk commented on Jun 3, 2021

    @cblackuk
    Contributor

    To me the error is correct, as it requires a certain format :-) the format provided does not match :-) but maybe I am missing something?

  2. changed the title [-]Usagesummary.ps1 does not properly handle [DateTime] varients for StartTime/EndTime[/-] [+]Usagesummary.ps1 does not properly handle [DateTime] variants for StartTime/EndTime[/+] on Jun 3, 2021
  3. easyveazie commented on Jun 3, 2021

    @easyveazie
    Author

    Chris Black (@cblackuk) I have added more context above.

  4. cblackuk commented on Jun 3, 2021

    @cblackuk
    Contributor

    I just realised that I use a completely custom version of all this and for 129 we run for example

    Get-AzsSubscriberUsage -ReportedStartTime (Get-Date (Get-Date).AddDays(-1) -Format "MM/dd/yyyy") -ReportedEndTime (Get-Date -Format "MM/dd/yyyy")
  5. cblackuk commented on Jun 3, 2021

    @cblackuk
    Contributor

    The cmdlet itself only validates on [DateTime]

     [OutputType([Microsoft.AzureStack.Management.Commerce.Admin.Models.UsageAggregate])]
                              [CmdletBinding()]
                              param(
                                  [Parameter(Mandatory = $false)]
                                  [System.String]
                                  $SubscriberId,
    
                                  [Parameter(Mandatory = $true)]
                                  [ValidateNotNullOrEmpty()]
                                  [System.DateTime]
                                  $ReportedStartTime,
    
                                  [Parameter(Mandatory = $false)]
                                  [System.String]
                                  [ValidateSet("Daily", "Hourly")]
                                  $AggregationGranularity,
    
                                  [Parameter(Mandatory = $false)]
                                  [int]
                                  $Skip = -1,
    
                                  [Parameter(Mandatory = $true)]
                                  [ValidateNotNullOrEmpty()]
                                  [System.DateTime]
                                  $ReportedEndTime,
    
                                  [Parameter(Mandatory = $false)]
                                  [System.String]
                                  $ContinuationToken,
    
                                  [Parameter(Mandatory = $false)]
                                  [int]
                                  $Top = -1
                              )

    Or to be more accurate on [DateTime] and not being empty and being provided:

                                  [Parameter(Mandatory = $true)]
                                  [ValidateNotNullOrEmpty()]
                                  [System.DateTime]
                                  $ReportedStartTime,
    
                                  [Parameter(Mandatory = $true)]
                                  [ValidateNotNullOrEmpty()]
                                  [System.DateTime]
                                  $ReportedEndTime,
    

    So if one works and the other one does not - it must be something to do with ARM post update?

  6. cblackuk commented on Jun 3, 2021

    @cblackuk
    Contributor

    Mike Veazie (@easyveazie) For laughs... what if you pass to it this instead?

    2021-20-05
    2021-01-06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions