Skip to content

Instantly share code, notes, and snippets.

@brettmillerb
Created January 18, 2022 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettmillerb/5769f0bb26f5ebecb0ac643749d8b33a to your computer and use it in GitHub Desktop.
Save brettmillerb/5769f0bb26f5ebecb0ac643749d8b33a to your computer and use it in GitHub Desktop.
PowerShell Azure Subscription Quota Percentage Helper Function
function Get-QuotaPercentage {
[CmdletBinding()]
param (
[Parameter(Mandatory,
ValueFromPipeline)]
$InputObject
)
process {
foreach ($item in $InputObject) {
if ($item[0].gettype().fullname -eq "Microsoft.Azure.Commands.Compute.Models.PSUsage") {
$name = $item.Name.LocalizedValue
}
elseif ($item[0].gettype().fullname -eq 'Microsoft.Azure.Commands.Management.Storage.Models.PSUsage') {
$name = $item.Name
}
[PSCustomObject]@{
Name = $name
CurrentValue = $item.CurrentValue
Limit = $item.Limit
PercentageUsed = if ($item.CurrentValue) { [math]::Round(($item.CurrentValue / $item.limit) * 100)} else { 0 }
Unit = $item.unit
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment