Need to check your Azure VM costs? Use this script

Most of the time, when we want to check consumption to keep an eye on our Azure VM costs, we use Azure Portal because it is easier to narrow down and get the number that you are looking for.

Sometimes, you may want to do a quick check on a given VM to identify the costs, and that is one of the requests that I received today. We have the Get-AzConsumptionUsageDetail cmdlet that helps exactly on that front. However, the output has a lot of information and lacks totals, which makes it harder when you need a simple answer like how much that VM cost last month or the cost so far this month.

Azure VM costs

I created a script that you provide the VM name, and it will give you the cost of the current cycle and the previous month.

You can use the following link to get access to the Azure VM costs script.

About The Author

1 thought on “Need to check your Azure VM costs? Use this script”

  1. Hi Anderson, I ran your script but received an error about a null value. Any clues as to why the previous month is having an issue?

    You cannot call a method on a null-valued expression.
    At C:\scripts\vmCostInfo.ps1:41 char:1
    + $TimeSchedule.Previous = $PreviousYear.ToString() + $PreviousMonth.to …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    VM Information: server-xxxx [ OKAY ]
    Current billing Cycle (202311) Monthly cost was 4.30 [ WARNING ]

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top