Forum Discussion

bharatTechie's avatar
bharatTechie
Copper Contributor
Jun 08, 2022

Format-Table, only show conditional data or Sort-Object in powershell

Hi All,   I am trying to format data using format-table but I also want to display the results only if PercentageUsed is more than 50%. Any Ideas?   Get-AzVmUsage -Location australiaeast | Format...
  • LainRobertson's avatar
    Jun 09, 2022

    bharatTechie 

     

    Get-AzVmUsage -Location australiaeast |
        Where-Object { $_.Limit -and $_.Limit -gt 0 -and $_.CurrentValue / $_.Limit -ge 0.5 } |
            ForEach-Object {
               [PSCustomObject] @{
                   Name = $_.name.LocalizedValue;
                   ResourceType = $_.ResourceType;
                   CurrentValue = $_.CurrentValue;
                   Limit = $_.Limit;
                   PercentageUsed = [math]::Round($_.CurrentValue * 100 / $_.Limit);
               }
            } | Format-Table -AutoSize

    Cheers,

    Lain

Resources