查询 Azure 时的 Powershell 过滤/格式化

标签 powershell azure filter command-line-interface

请帮助格式化命令的输出: 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

这是结果。

enter image description here

根本原因是Name包含两个子值:ValueLocalizedValue。如果直接选择它们,您将获得 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}

enter image description here

更新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'}}

enter image description here

关于查询 Azure 时的 Powershell 过滤/格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45331048/

相关文章:

azure - 无法在 Azure Devops 上运行的 powershell 脚本中访问 Azure Key Vault secret

powershell - 将 Powershell 开关传递到 Azure 资源管理器模板 (ARM)

amazon-web-services - 使用 powershell 对 AWS EC2 的 ssh 登录失败进行故障排除

asp.net-mvc - 长距离 OSM 路由,如何处理所有这些数据?

regex - 在 Julia 的过滤器中使用正则表达式

c# - 将 datatables.js 与 asp.net gridview 集成

powershell - 选择字符串-上下文并在数据中查找电子邮件地址

azure - 在 Azure 服务总线上正确自动更新锁

azure - 身份验证和授予授权后 OpenIdConnect 错误重定向

iOS - 将 tableView 中的 numberOfSections 设置为过滤单元格的数量 (Swift)