The Power of PowerShell: Calculating Azure VMware Solution (AVS) Costs

Share on:

Gone are the days of manual calculations and complex spreadsheets to estimate costs. With the capabilities of PowerShell and automation tools we have the ability to streamline the collection of data. Through this blog I will guide you through the steps of utilizing PowerShell to calculate Azure VMware Solution costs.

When trying to collect azure costs, you will usually start with the Azure Pricing Calculator this allows you to pick an Azure Service, Region and Amount and it gives you the cost. However sometimes using the web portal can be timely when you just want to pull down a cost for a region quickly.

Alongside the user interface, Azure also has a Retail Prices API. I oiginally planned to use this for my example, but had already used a different method in the past and trying to navigate through the pagination was a built difficult, so in the future I may revisit this script.

With that being said, I opted to take a “legacy” approach to grabbing the overall costs for an AVS solution. The code snippet is below, but the structure of the script is as follows:

  1. Calculate 730 hours per Month
  2. Pull down AVS Pricing from https://azure.microsoft.com/api/v2/pricing/azure-vmware/calculator/
  3. Parse it, make it pretty and format it.
Param (
[Parameter(Mandatory)]$Region,
[Parameter(Mandatory)]$NumberofNodes
)
$hourspermonth = "730"
$avsrequest = Invoke-WebRequest -Uri "https://azure.microsoft.com/api/v2/pricing/azure-vmware/calculator/"
$avsoffers = $avsrequest.Content | ConvertFrom-Json
$av36payg = $avsoffers.offers.'av36-payg'.prices.$region.value * $hourspermonth * $NumberofNodes
$av36oneyear = $avsoffers.offers.'av36-one-year'.prices.$region.value * $hourspermonth * $NumberofNodes
$av36threeyear = $avsoffers.offers.'av36-three-year'.prices.$region.value * $hourspermonth * $NumberofNodes
$av36ppayg = $avsoffers.offers.'av36p-payg'.prices.$region.value * $hourspermonth * $NumberofNodes
$av36poneyear = $avsoffers.offers.'av36p-one-year'.prices.$region.value * $hourspermonth * $NumberofNodes
$av36pthreeyear = $avsoffers.offers.'av36p-three-year'.prices.$region.value * $hourspermonth * $NumberofNodes
$av52payg = $avsoffers.offers.'av52-payg'.prices.$region.value * $hourspermonth * $NumberofNodes
$av52oneyear = $avsoffers.offers.'av52-one-year'.prices.$region.value * $hourspermonth * $NumberofNodes
$av52threeyear = $avsoffers.offers.'av52-three-year'.prices.$region.value * $hourspermonth * $NumberofNodes
$av36paygcost = '{0:C}' -f $av36payg
$av36oneyearcost = '{0:C}' -f $av36oneyear
$av36threeyearcost = '{0:C}' -f $av36threeyear
$av36ppaygcost = '{0:C}' -f $av36ppayg
$av36poneyearcost = '{0:C}' -f $av36poneyear
$av36pthreeyearcost = '{0:C}' -f $av36pthreeyear
$av52paygcost = '{0:C}' -f $av52payg
$av52oneyearcost= '{0:C}' -f $av52oneyear
$av52threeyearcost = '{0:C}' -f $av52threeyear
if ($av36paygcost) {Write-Host -ForegroundColor Green "Ondemand AV36 Cost per Month:" $av36paygcost} else {(Write-Host -ForegroundColor Red "AV36 Not available in $region")}
if ($av36oneyearcost) {Write-Host -ForegroundColor Green "1year AV36 Cost per Month" $av36oneyearcost} else {(Write-Host -ForegroundColor Red "AV36 Not available in $region")}
if ($av36threeyearcost) {Write-Host -ForegroundColor Green "3year AV36 Cost per Month" $av36threeyearcost} else {(Write-Host -ForegroundColor Red "AV36 Not available in $region")}
if ($av36ppaygcost) {Write-Host -ForegroundColor Green "Ondemand AV36P Cost per Month" $av36ppaygcost} else {(Write-Host -ForegroundColor Red "AV36P Not available in $region")}
if ($av36poneyearcost) {Write-Host -ForegroundColor Green "1year AV36P Cost per Month" $av36poneyearcost} else {(Write-Host -ForegroundColor Red "AV36P Not available in $region")}
if ($av36pthreeyearcost) {Write-Host -ForegroundColor Green "3year AV36P Cost per Month" $av36pthreeyearcost} else {(Write-Host -ForegroundColor Red "AV36P Not available in $region")}
if ($av52paygcost) {Write-Host -ForegroundColor Green "Ondemand AV52 Cost per Month" $av52paygcost} else {(Write-Host -ForegroundColor Red "AV52 Not available in $region")}
if ($av52oneyearcost) {Write-Host -ForegroundColor Green "1year AV52 Cost per Month" $av52oneyearcost} else {(Write-Host -ForegroundColor Red "AV52 Not available in $region")}
if ($av52threeyearcost) {Write-Host -ForegroundColor Green "3year AV52 Cost per Month" $av52threeyearcost} else {(Write-Host -ForegroundColor Red "AV52 Not available in $region")}
view raw GetAVSCost.ps1 hosted with ❤ by GitHub

All it takes is running the script with the parameters for Region and Number of nodes and you will see the output of the nodes that are available in that region and the On-Demand, 1 Year Reserve and 3 Year Reserve Pricing.

1./getavsCost.ps1 -region us-central -NumberofNodes 1
pwsh

In this case we can see the cost for the AV36P in us-east. It is the only node type available and matches the price above we recieved from the Azure Cost UI.

In regions that support multiple nodes, you will see the pricing as well.

In closing, costs can vary from region to region and node type to node type. Its important to be easily able to pull down a cost when needed in a format that is automated.

Interested in another solutions cost? Let me know!

See Also