如何强制Powershell使用新的Azure订阅

时间:2022-09-23 07:42:30

I have two subscription one with old cloud service and other is with new cloud service. I am using Powershell to access my new subscription. I have downloaded latest .publishsettings and set it using Import-AzurePublishSettingsFile. My problem is that I always get the old subscription set and could not figureout how to force powershell to use my new subscription.

我有两个订阅,一个是旧的云服务,另一个是新的云服务。我正在使用Powershell访问我的新订阅。我已经下载了最新的.publishsettings并使用Import-AzurePublishSettingsFile进行设置。我的问题是我总是得到旧的订阅集,无法弄清楚如何强制PowerShell使用我的新订阅。

3 个解决方案

#1


7  

With new Powershell commands you would need to set which particular subscription you would want to use. The steps are as below:

使用新的Powershell命令,您需要设置要使用的特定订阅。步骤如下:

  1. Import-AzurePublishSettingsFile yourpublishsettings.publishsettings
  2. 导入-AzurePublishSettingsFile yourpublishsettings.publishsettings
  3. Get-AzureSubscription (this will give you the list of subscription)
  4. Get-AzureSubscription(这将为您提供订阅列表)
  5. Select-AzureSubscription _select_subscription_name (this way you can set which particular subscription you want to use)
  6. 选择-AzureSubscription _select_subscription_name(这样您就可以设置要使用的特定订阅)

This should work!!

这应该工作!!

#2


8  

Just to clarify, there are two kinds of 'special' subscriptions, the 'current' subscription (which is the subscription used for any command in the current PowerShell session), and the Defaul subscription, which is the subscription used even after the current PowerShell session ends.

为了澄清,有两种“特殊”订阅,“当前”订阅(用于当前PowerShell会话中任何命令的订阅)和Defaul订阅,即使在当前PowerShell之后也使用的订阅会话结束。

using Select-AzureSubscription <subscription-name> will set the current subscription. If you'd like to change the subscription across sessions, use Select-AzureSubscription -Default <subscription name>

使用Select-AzureSubscription 将设置当前订阅。如果您想跨会话更改订阅,请使用Select-AzureSubscription -Default

#3


2  

This answer is for the classic Azure management. If you're on the new ARM then you want to do something like

这个答案适用于经典的Azure管理。如果你使用新的ARM,那么你想要做类似的事情

Login-AzureRmAccount
Get-AzureRmSubscription
Set-AzureRmContext -SubscriptionId blah

where blah is the subscription ID from the second command

其中blah是第二个命令的订阅ID

#1


7  

With new Powershell commands you would need to set which particular subscription you would want to use. The steps are as below:

使用新的Powershell命令,您需要设置要使用的特定订阅。步骤如下:

  1. Import-AzurePublishSettingsFile yourpublishsettings.publishsettings
  2. 导入-AzurePublishSettingsFile yourpublishsettings.publishsettings
  3. Get-AzureSubscription (this will give you the list of subscription)
  4. Get-AzureSubscription(这将为您提供订阅列表)
  5. Select-AzureSubscription _select_subscription_name (this way you can set which particular subscription you want to use)
  6. 选择-AzureSubscription _select_subscription_name(这样您就可以设置要使用的特定订阅)

This should work!!

这应该工作!!

#2


8  

Just to clarify, there are two kinds of 'special' subscriptions, the 'current' subscription (which is the subscription used for any command in the current PowerShell session), and the Defaul subscription, which is the subscription used even after the current PowerShell session ends.

为了澄清,有两种“特殊”订阅,“当前”订阅(用于当前PowerShell会话中任何命令的订阅)和Defaul订阅,即使在当前PowerShell之后也使用的订阅会话结束。

using Select-AzureSubscription <subscription-name> will set the current subscription. If you'd like to change the subscription across sessions, use Select-AzureSubscription -Default <subscription name>

使用Select-AzureSubscription 将设置当前订阅。如果您想跨会话更改订阅,请使用Select-AzureSubscription -Default

#3


2  

This answer is for the classic Azure management. If you're on the new ARM then you want to do something like

这个答案适用于经典的Azure管理。如果你使用新的ARM,那么你想要做类似的事情

Login-AzureRmAccount
Get-AzureRmSubscription
Set-AzureRmContext -SubscriptionId blah

where blah is the subscription ID from the second command

其中blah是第二个命令的订阅ID