【问题标题】:Get the value of the app service plan using Powershell使用 Powershell 获取应用服务计划的价值
【发布时间】:2020-04-23 15:56:44
【问题描述】:

我正在尝试使用 Powershell 获取应用服务计划的唯一名称值。

查询:

Get-AzResource -ResourceGroupName "entaddinqagrouptwm" -ResourceType Microsoft.Web/serverfarms | ft

输出是:

Name                       ResourceGroupName  ResourceType              Location
----                       -----------------  ------------              --------
ntaddinqaapptwmeastusplan1 entaddinqagrouptwm Microsoft.Web/serverFarms eastus
ntaddinqaapptwmeastusplan2 entaddinqagrouptwm Microsoft.Web/serverFarms eastus

我的代码:

$resourceHash = Get-AzResource -ResourceGroupName "entaddinqagrouptwm" -ResourceType Microsoft.Web/serverfarms | ft
Write-Host "Apps : " $resourceHash.GetValue(0)

我得到的结果:

Apps :  Microsoft.PowerShell.Commands.Internal.Format.FormatStartData

我想要的结果:

ntaddinqaapptwmeastusplan1
ntaddinqaapptwmeastusplan2

这样我就可以在结果上使用for每个循环,并对每个应用计划执行操作。

【问题讨论】:

  • 如果您想进行进一步的处理,包括检索对象及其属性,请不要使用format-* 命令,如ft(又名format-table)。这些应该仅用于显示目的。您应该分配 $resourceHash 而不使用 | ft。如果您想稍后在控制台中显示表格,则只需使用$resourceHash | ft

标签: azure powershell azure-resource-group


【解决方案1】:

我相信下面的代码就是您所需要的。无需“格式化列表”。您只需要正确选择 $resourceHash 对象上的属性即可。

    $resourceHash = Get-AzResource -ResourceGroupName "entaddinqagrouptwm" -ResourceType Microsoft.Web/serverfarms
    Write-Host "Apps : " $resourceHash.Name

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-20
    • 2020-04-29
    • 2020-10-29
    • 1970-01-01
    相关资源
    最近更新 更多