Created
January 18, 2022 15:27
-
-
Save brettmillerb/5769f0bb26f5ebecb0ac643749d8b33a to your computer and use it in GitHub Desktop.
PowerShell Azure Subscription Quota Percentage Helper Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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