请帮助格式化命令的输出: Get-AzureRmVMUsage -位置“美国西部”
现在显示:
Name Current Value Limit Unit
Availability Sets 77 322000 Count
Total Regional Cores 4159 323000 Count
Virtual Machines 999 32220000 Count
如何通过管道/过滤它,使其仅显示区域核心总数的值?
选择名称显示以下内容:
Get-AzureRmVMUsage -Location "East US" -Verbose | Select Name
Name
----
Microsoft.Azure.Management.Compute.Models.UsageName
Microsoft.Azure.Management.Compute.Models.UsageName
谢谢, 德米特里
最佳答案
您可以使用以下命令。
(Get-AzureRmVMUsage -Location "East US"|select -ExpandProperty Name).LocalizedValue
这是结果。
根本原因是Name
包含两个子值:Value
和LocalizedValue
。如果直接选择它们,您将获得 Microsoft.Azure.Management.Compute.Models.UsageName
。
更新:
So how do I get the exact value that corresponds to Total Regonal Cores
只需使用以下命令。
$names= Get-AzureRmVMUsage -Location "East US"
foreach($name in $names) {$results = [pscustomobject]@{'name'=$name.name.LocalizedValue;'value'=$name.CurrentValue};$results}
更新2:
There is a Total Regional Cores variable that holds the value of 5 in your example. I want the formatting to show just this value without showing anything else
foreach($name in $names) {$results = [pscustomobject]@{'name'=$name.name.LocalizedValue;'value'=$name.CurrentValue};$results | ?{$_.name -eq 'Total Regional Cores'}}
关于查询 Azure 时的 Powershell 过滤/格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45331048/