【发布时间】:2022-01-17 01:38:10
【问题描述】:
所以,我有资源组名称,我想以编程方式(使用 powershell)将订阅设置为传入资源组。
当我执行Get-AzResourceGroup 时,我得到包含订阅ID 作为长字符串/subscriptions/<subscription id here>/resourceGroups/resourcegroupname 的一部分的ResourceId。有没有办法从该字符串中提取订阅 ID?
【问题讨论】:
所以,我有资源组名称,我想以编程方式(使用 powershell)将订阅设置为传入资源组。
当我执行Get-AzResourceGroup 时,我得到包含订阅ID 作为长字符串/subscriptions/<subscription id here>/resourceGroups/resourcegroupname 的一部分的ResourceId。有没有办法从该字符串中提取订阅 ID?
【问题讨论】:
您可以通过触发以下来获取您的订阅 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]
【讨论】: