【问题标题】:Not able to select subscription ID in azure无法在 Azure 中选择订阅 ID
【发布时间】:2018-02-09 20:14:22
【问题描述】:

我正在使用下面的代码在 Power shell 脚本中选择订阅 ID,但是当我点击订阅 ID 时它没有选择...

$subscriptionId = (Get-AzureRmSubscription | Out-GridView -Title '选择 Azure 订阅:'-PassThru).SubscriptionId Select-AzureRmSubscription -SubscriptionId $subscriptionId

【问题讨论】:

    标签: azure subscription azure-powershell cmdlet


    【解决方案1】:

    我们可以使用这个脚本来做:

    $subscriptionId = (Get-AzureRmSubscription | Out-GridView -Title 'Select Azure Subscription:' -PassThru).Id 
    Select-AzureRmSubscription -SubscriptionId $subscriptionId
    

    我们应该使用Id,而不是SubscriptionId,我们可以在这里找到输出:

    PS C:\Users\v-jianye> Get-AzureRmSubscription
    
    Name     : Visual Studio Ultimate with MSDN
    Id       : 5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx
    TenantId : 1fcfxxxx-xxx-4c99-9449-d8e18bf8xxxx
    State    : Enabled
    

    【讨论】:

    • 谢谢 Jason,脚本在运行时提供了从多个订阅中为用户选择订阅 ID 的选项,所以现在我将使用 $subid = ... ?我说的对吗?
    • 不,在你的脚本中,$subscriptionId 包含nameId、'TenantId' 和stateSelect-AzureRmSubscription -SubscriptionId 需要ID,所以我们可以使用$subscriptionId.Id,或者这样使用$subscriptionId = (Get-AzureRmSubscription | Out-GridView -Title 'Select Azure Subscription:' -PassThru).Id,就可以得到$subscriptionId的订阅Id。
    猜你喜欢
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-14
    • 1970-01-01
    • 2021-02-25
    • 2016-05-28
    相关资源
    最近更新 更多