@@ -260,7 +260,7 @@ param(
260260)
261261
262262 process {
263- $ApiVersion = ' 2019-11-01-preview '
263+ $ApiVersion = ' 2019-11-01'
264264
265265 $URL = ' '
266266 if ($PSBoundParameters.ContainsKey (' ExternalCloudProviderType' )) {
@@ -273,7 +273,7 @@ param(
273273 $ErrorMessage = ' Id in input object should not be empty.'
274274 throw [System.IO.FileNotFoundException ] $ErrorMessage
275275 }
276- $match = [System.Text.RegularExpressions ].Regex(" ^/ (?<scope>[^/] +)/providers/Microsoft.CostManagement/query$" ).Match($ResourceId );
276+ $match = [System.Text.RegularExpressions ].Regex(" (?<scope>. +)/providers/Microsoft.CostManagement/query$" ).Match($ResourceId );
277277 if (-not $match.Success )
278278 {
279279 throw [System.IO.FileNotFoundException ] " Invalid identity for URI '/{scope}/providers/Microsoft.CostManagement/query'"
@@ -283,47 +283,62 @@ param(
283283 $URL = [System.Uri ]::New([System.Text.RegularExpressions.Regex ]::Replace(
284284 " https://management.azure.com/$Scope /providers/Microsoft.CostManagement/query?api-version=$ApiVersion " , " \\?&*$|&*$|(\\?)&+|(&)&+" , " $1$2 " ))
285285 }
286+ $URL = $URL -replace " https://management.azure.com/" , " "
286287
287- $Request = [Microsoft.Azure.PowerShell.Cmdlets.Cost.Models.Api20191101.QueryDefinition ]::New()
288- if ($PSBoundParameters.ContainsKey (' ConfigurationColumn' )) {
289- $Request.ConfigurationColumn = $ConfigurationColumn
290- }
291- if ($PSBoundParameters.ContainsKey (' DatasetAggregation' )) {
292- $Request.DatasetAggregation = $DatasetAggregation
293- }
294- if ($PSBoundParameters.ContainsKey (' DatasetFilter' )) {
295- $Request.DatasetFilter = $DatasetFilter
296- }
297- if ($PSBoundParameters.ContainsKey (' DatasetGranularity' )) {
298- $Request.DatasetGranularity = $DatasetGranularity
299- }
300- if ($PSBoundParameters.ContainsKey (' DatasetGrouping' )) {
301- $Request.DatasetGrouping = $DatasetGrouping
302- }
303- if ($PSBoundParameters.ContainsKey (' TimePeriodFrom' )) {
304- $Request.TimePeriodFrom = $TimePeriodFrom
305- }
306- if ($PSBoundParameters.ContainsKey (' TimePeriodTo' )) {
307- $Request.TimePeriodTo = $TimePeriodTo
308- }
309- if ($PSBoundParameters.ContainsKey (' Timeframe' )) {
310- $Request.Timeframe = $Timeframe
311- }
312- if ($PSBoundParameters.ContainsKey (' Type' )) {
313- $Request.Type = $Type
288+ $Request = [Microsoft.Azure.PowerShell.Cmdlets.Cost.Models.Api20191101.QueryDefinition ]::New()
289+ if ($PSBoundParameters.ContainsKey (' ConfigurationColumn' )) {
290+ $Request.ConfigurationColumn = $ConfigurationColumn
291+ }
292+ if ($PSBoundParameters.ContainsKey (' DatasetAggregation' )) {
293+ $Request.DatasetAggregation = $DatasetAggregation
294+ }
295+ if ($PSBoundParameters.ContainsKey (' DatasetFilter' )) {
296+ $Request.DatasetFilter = $DatasetFilter
297+ }
298+ if ($PSBoundParameters.ContainsKey (' DatasetGranularity' )) {
299+ $Request.DatasetGranularity = $DatasetGranularity
300+ }
301+ if ($PSBoundParameters.ContainsKey (' DatasetGrouping' )) {
302+ $Request.DatasetGrouping = $DatasetGrouping
303+ }
304+ if ($PSBoundParameters.ContainsKey (' TimePeriodFrom' )) {
305+ $Request.TimePeriodFrom = $TimePeriodFrom
306+ }
307+ if ($PSBoundParameters.ContainsKey (' TimePeriodTo' )) {
308+ $Request.TimePeriodTo = $TimePeriodTo
309+ }
310+ if ($PSBoundParameters.ContainsKey (' Timeframe' )) {
311+ $Request.Timeframe = $Timeframe
312+ }
313+ if ($PSBoundParameters.ContainsKey (' Type' )) {
314+ $Request.Type = $Type
315+ }
316+ $ResponseContent = (Invoke-AzRest - Path $URL - Payload $Request.ToJsonString () - Method POST).Content | ConvertFrom-Json
317+ if ($Null -ne $ResponseContent.Error ) {
318+ throw $ResponseContent.Error.Message
319+ }
320+ $Result = [Microsoft.Azure.PowerShell.Cmdlets.Cost.Models.Api20191101.QueryResult ]::New()
321+ $Result.NextLink = $ResponseContent.Properties.NextLink
322+
323+ $ColumnList = New-Object System.Collections.Generic.List[Microsoft.Azure.PowerShell.Cmdlets.Cost.Models.Api20191101.IQueryColumn ]
324+ foreach ($Column in $ResponseContent.Properties.Columns ) {
325+ Write-Host $Column.ToString ()
326+ $QueryColumn = [Microsoft.Azure.PowerShell.Cmdlets.Cost.Models.Api20191101.QueryColumn ]::New()
327+ $QueryColumn.Name = $Column.Name
328+ $QueryColumn.Type = $Column.Type
329+ $ColumnList.Add ($QueryColumn )
330+ }
331+ $Result.Column = $ColumnList
332+
333+ $RowList = New-Object System.Collections.Generic.List[System.Collections.Generic.List [string ]]
334+ foreach ($Row in $ResponseContent.Properties.Rows ) {
335+ $QueryRow = New-Object System.Collections.Generic.List[string ]
336+ foreach ($Item in $Row ) {
337+ $QueryRow.Add ($Item.ToString ())
314338 }
315- Write-Host $URL
316- $Response = Invoke-AzRest - Path $URL $RequestBody $Request | ConvertFrom-Json
317- $Result = [Microsoft.Azure.PowerShell.Cmdlets.Cost.Models.Api20191101.QueryResult ]::New()
318- $Result.Column = $Response.Columns
319- $Result.Row = $Response.Rows
320- # foreach ($RawRow in $Response.Row) {
321- # $Row = New-Object System.Collections.ArrayList
322- # for ($Index=0; $Index -lt $Result.Column.Length; $Index++) {
323- # $Column = $Result.Column[$Index]
324-
325- # }
326- # }
327- return $Result
339+ $RowList.Add ($QueryRow )
340+ }
341+ $Result.Row = $RowList
342+ return $Result
328343 }
329344}
0 commit comments