【问题标题】:How to manage multiple AzureRM accounts with Powershell如何使用 Powershell 管理多个 AzureRM 帐户
【发布时间】:2016-04-18 11:45:28
【问题描述】:

我尝试使用 Login-AzureRmAccount 和 Add-AzureRmAccount 登录到我的 Azure 帐户。我有两个,很容易通过 Add-AzureAccount 添加它们并使用 Select-Azuresubscription 管理活动的和默认的。

每次我执行 Add-AzureRmAccount 时,使用 RM cmdlet 都会覆盖之前经过身份验证的命令。这让我很难在私人和公司 azure 帐户之间切换。

有什么解决方案吗? 我正在使用 PowerShell 库来更新 Azure 和 AzureRM 模块并使用最新的。

【问题讨论】:

    标签: powershell azure azure-resource-manager


    【解决方案1】:

    官方的做法是这样的

    $profile1 = Login-AzureRmAccount 
    $profile2 = Login-AzureRmAccount
    
    Select-AzureRmProfile -Profile $profile2
    

    然后您可以使用

    将配置文件保存到磁盘
    Save-AzureRmProfile -Profile $profile1 -Path e:\ps\profile1.json 
    

    然后您可以使用

    加载
    Select-AzureRmProfile -Path e:\ps\profile1.json 
    

    不过,我个人的方法是创建一个模块,该模块提供一个以 profile1、profile2 等为参数的 cmdlet。然后它将下载和解密凭据并将它们提供给 Add-AzureRMAccount(这样我可以使用来自各种位置的相同凭据文件)

    【讨论】:

      【解决方案2】:

      使用Login-AzureRMAccout分别登录两个账号。然后使用 Get-AzureRmSubscription 查看订阅信息并记下两个 TenantId。

      要在私人和公司 Azure 帐户之间切换,您可以使用指定 TenantId 参数

       $loadersubscription = Get-AzureRmSubscription -SubscriptionName $YourSubscriptionName -TenantId $YourAssociatedSubscriptionTenantId
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-05
        • 2014-11-19
        • 2020-01-08
        • 1970-01-01
        • 2011-04-07
        • 1970-01-01
        相关资源
        最近更新 更多