【问题标题】:How can I get the Subscription Name if i know the resource Group Name using Powershell如果我知道使用 Powershell 的资源组名称,如何获取订阅名称
【发布时间】:2022-01-17 01:38:10
【问题描述】:

所以,我有资源组名称,我想以编程方式(使用 powershell)将订阅设置为传入资源组。 当我执行Get-AzResourceGroup 时,我得到包含订阅ID 作为长字符串/subscriptions/<subscription id here>/resourceGroups/resourcegroupname 的一部分的ResourceId。有没有办法从该字符串中提取订阅 ID?

【问题讨论】:

    标签: powershell subscription


    【解决方案1】:

    您可以通过触发以下来获取您的订阅 ID。您还需要安装 azure cli。

    az account list  --refresh --query "[?contains(name, 'YOUR_SUBSCRIPTION')].id"
    

    您还可以从powershell 拆分输出。

    $myinput= "/subscriptions/xxxxxx-xxxxxx-xxxxxx-xxxxx-xxxxxx/resourceGroups/resourcegroupname".Split("/")
    
    Write-Host $myinput[2]
    

    【讨论】:

    • 谢谢!那行得通
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 2019-01-19
    • 2015-01-30
    • 2011-03-29
    • 1970-01-01
    相关资源
    最近更新 更多