Skip to content

Invoke-AzCostManagementQuery - ConvertFrom-Json failed with error: Unexpected Character #28390

@iHatch-mcs

Description

@iHatch-mcs

Description

When attempting to run a usage query for a single storage account resource, I get an error for a convertfrom-Json taking place in the function

Issue script & Debug output

PS C:\Users\IHatch> Invoke-AzCostManagementQuery -Scope '/subscriptions/*****/resourceGroups/*****/providers/Microsoft.Storage/storageAccounts/*****' -TimeFrame LastMonth -Type Usage -DataSetGranularity 'Daily'
ConvertFrom-Json: C:\Program Files\WindowsPowerShell\Modules\Az.CostManagement\0.4.2\CostManagement.Autorest\custom\Invoke-AzCostManagementQuery.ps1:246:92
Line |
 246 |-Path $URL -Payload $Payload -Method POST).Content | ConvertFrom-Json
     |                                                         ~~~~~~~~~~~~~~~~
     | Conversion from JSON failed with error: Unexpected character encountered while parsing value: T. Path '', line 0, position 0.

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.2
PSEdition                      Core
GitCommitId                    7.5.2
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     5.2.0                 Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script     0.4.2                 Az.CostManagement                   {Get-AzCostManagementExport, Get-AzCostManagementExportExecutionHistory, Invoke-AzCostManagementExecuteExport, Invoke-AzCostManagementQuery…}

Error output

HistoryId: 4

Message        : Conversion from JSON failed with error: Unexpected character encountered while parsing value: T. Path '', line 0, position 0.
StackTrace     :    at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, Boolean returnHashtable, Nullable`1 maxDepth, JsonDateKind jsonDateKind, ErrorRecord& error)
                    at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input)
                    at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.EndProcessing()
                    at System.Management.Automation.CommandProcessorBase.Complete()
Exception      : System.ArgumentException
InvocationInfo : {ConvertFrom-Json}
Line           :     $ResponseContent = (Invoke-AzRest -Path $URL -Payload $Payload -Method POST).Content | ConvertFrom-Json

Position       : At C:\Program Files\WindowsPowerShell\Modules\Az.CostManagement\0.4.2\CostManagement.Autorest\custom\Invoke-AzCostManagementQuery.ps1:246 char:92
                 +-Path $URL -Payload $Payload -Method POST).Content | ConvertFrom-Json
                 +                                                        ~~~~~~~~~~~~~~~~
HistoryId      : 4

Message        : Unexpected character encountered while parsing value: T. Path '', line 0, position 0.
StackTrace     :    at Newtonsoft.Json.JsonTextReader.ParseValue()
                    at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
                    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
                    at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
                    at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
                    at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, Boolean returnHashtable, Nullable`1 maxDepth, JsonDateKind jsonDateKind, ErrorRecord& error)
Exception      : Newtonsoft.Json.JsonReaderException
InvocationInfo : {ConvertFrom-Json}
Line           :     $ResponseContent = (Invoke-AzRest -Path $URL -Payload $Payload -Method POST).Content | ConvertFrom-Json

Position       : At C:\Program Files\WindowsPowerShell\Modules\Az.CostManagement\0.4.2\CostManagement.Autorest\custom\Invoke-AzCostManagementQuery.ps1:246 char:92
                 +-Path $URL -Payload $Payload -Method POST).Content | ConvertFrom-Json
                 +                                                        ~~~~~~~~~~~~~~~~
HistoryId      : 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Cost Management - QueryAll issues in cost management and Consumption for query API associated to tags, dimensions and forecService AttentionThis issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reported

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions