I am using the below command to fetch the Azure Consumption Detail. However, this seems to be not working now. Can someone tell me, if I missing out on anything?
PS C:\Windows\system32> Get-AzBillingPeriod -MaxCount 3
WARNING: Upcoming breaking changes in the cmdlet 'Get-AzBillingPeriod' :
The cmdlet is being deprecated. There will be no replacement for it.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other
information on breaking changes in Azure PowerShell.
Name : 202203-1
BillingPeriodStartDate : 2022-01-02
BillingPeriodEndDate : 2022-02-01
Name : 202202-1
BillingPeriodStartDate : 2021-12-02
BillingPeriodEndDate : 2022-01-01
PS C:\Windows\system32> Get-AzConsumptionUsageDetail -BillingPeriodName 202202-1
Get-AzConsumptionUsageDetail : Operation returned an invalid status code 'BadRequest'
At line:1 char:1
Get-AzConsumptionUsageDetail -BillingPeriodName 202202-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : CloseError: (:) [Get-AzConsumptionUsageDetail], ErrorResponseException
FullyQualifiedErrorId : Microsoft.Azure.Commands.Consumption.Cmdlets.UsageDetails.GetAzureRmConsumptionUsageDetail
Resolution:
If I specify Start & End Date then I get the results correctly. So I feel, if the billing date is not getting started from 1st of Every Month then also we get the above error I guess. In that case, we need to find the Start and End Date to get the results.
Get-AzConsumptionUsageDetail -StartDate 2021-12-02 -EndDate 2022-01-01
CodePudding user response:
Currently , the Powershell API to get subscription consumption details only supports Enterprise Subscriptions. There is also a 
If You run command with debug then you can also see why it is giving bad request :
Get-AzConsumptionUsageDetail -BillingPeriodName 202202-1 -debug
Update :
As Gokulnath Kumar mentioned , In Pay-as-you-go subscription it seems to work if provide start date and end date with the command as per your Billing Period Start Date and Billing Period End Date like below :
Get-AzConsumptionUsageDetail -StartDate 2021-11-27 -EndDate 2021-12-26


