Azure をPower Shell で操作するときのアカウントの切り替えなど | あいうえお

あいうえお

  if (Count($misstake) > 0) then GOTO Error_Comment

以前に、Powershell で azure の Webサイトを構築する という記事を書きました。


この時初めて、AzureをPower Shellで操作したので気にしてなかったのですが、

複数アカウント使うケースが出てきたので、その忘備録です。


1.アカウントの追加


PS C:\> Add-AzureAccount
詳細: Account "アカウント2" has been added.
詳細: Subscription "無料評価版" is selected as the default subscription.
詳細: To view all the subscriptions, please use Get-AzureSubscription.
詳細: To switch to a different subscription, please use Select-AzureSubscription.


コマンドを実行すると、GUIでAzureの認証画面が出てきます。

それが成功すると、詳細ってところのログが出てきました。


このPCでは、前回無料アカウントをぶら下げたので、

すでに選択されている初期サブスクリプションの名称が無料評価版だよ。

使ってる、サブスクリプションを見たかったら、「Get-AzureSubscription」をやってね。

処理対象のサブスクリプションを変えたかったら、「Select-AzureSubscription」使ってね

って書いてありますね。


2.アカウントの確認


PS C:\> Get-AzureAccount

Name ActiveDirectories
---- -----------------
アカウント1   {{ ActiveDirectoryTenantId = xxxxxxxxxxxxxx...

アカウント2    {{ ActiveDirectoryTenantId = zzzzzzzzzzzzzz...



3.サブスクリプションの確認


PS C:\> Get-AzureSubscription


SubscriptionName : 無料評価版
SubscriptionId : XXXXXXXXXXXXXXXXXX
ServiceEndpoint : https://management.core.windows.net/
ResourceManagerEndpoint : https://management.azure.com/
GalleryEndpoint : https://gallery.azure.com/
ActiveDirectoryEndpoint : https://login.windows.net/
ActiveDirectoryTenantId : xxxxxxxxxxxxxxxxxx
IsDefault : True
Certificate :
CurrentStorageAccountName :
ActiveDirectoryUserId : アカウント1
TokenProvider : Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication.AdalTokenProvider

SubscriptionName : Visual Studio Premium with MSDN
SubscriptionId : ZZZZZZZZZZZZZZZZZZ
ServiceEndpoint : https://management.core.windows.net/
ResourceManagerEndpoint : https://management.azure.com/
GalleryEndpoint : https://gallery.azure.com/
ActiveDirectoryEndpoint : https://login.windows.net/
ActiveDirectoryTenantId : zzzzzzzzzzzzzzzzzz
IsDefault : False
Certificate :
CurrentStorageAccountName :
ActiveDirectoryUserId : アカウント2
TokenProvider : Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication.AdalTokenProvider


4.初期選択サブスクリプションの変更


PS C:\> Select-AzureSubscription -Default "Visual Studio Premium with MSDN"
PS C:\>
PS C:\>
PS C:\> Get-AzureSubscription

SubscriptionName : 無料評価版
SubscriptionId : XXXXXXXXXXXXXXXXXX
ServiceEndpoint : https://management.core.windows.net/
ResourceManagerEndpoint : https://management.azure.com/
GalleryEndpoint : https://gallery.azure.com/
ActiveDirectoryEndpoint : https://login.windows.net/
ActiveDirectoryTenantId : xxxxxxxxxxxxxxxxxx
IsDefault : False
Certificate :
CurrentStorageAccountName :
ActiveDirectoryUserId : アカウント1
TokenProvider : Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication.AdalTokenProvider

SubscriptionName : Visual Studio Premium with MSDN
SubscriptionId : ZZZZZZZZZZZZZZZZZZ
ServiceEndpoint : https://management.core.windows.net/
ResourceManagerEndpoint : https://management.azure.com/
GalleryEndpoint : https://gallery.azure.com/
ActiveDirectoryEndpoint : https://login.windows.net/
ActiveDirectoryTenantId : zzzzzzzzzzzzzzzzzz
IsDefault : True
Certificate :
CurrentStorageAccountName :
ActiveDirectoryUserId : アカウント2
TokenProvider : Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication.AdalTokenProvider


5.サブスクリプションの削除


PS C:\> Remove-AzureSubscription "無料評価版"

確認
Are you sure you want to remove subscription '無料評価版'?
[Y] はい(Y) [N] いいえ(N) [S] 中断(S) [?] ヘルプ (既定値は "Y"): y
PS C:\>
PS C:\>
PS C:\> Get-AzureSubscription

SubscriptionName : Visual Studio Premium with MSDN
SubscriptionId : ZZZZZZZZZZZZZZZZZZ
ServiceEndpoint : https://management.core.windows.net/
ResourceManagerEndpoint : https://management.azure.com/
GalleryEndpoint : https://gallery.azure.com/
ActiveDirectoryEndpoint : https://login.windows.net/
ActiveDirectoryTenantId : zzzzzzzzzzzzzzzzzz
IsDefault : True
Certificate :
CurrentStorageAccountName :
ActiveDirectoryUserId : アカウント2
TokenProvider : Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication.AdalTokenProvider



PS C:\> Get-AzureAccount

Name ActiveDirectories
---- -----------------
アカウント2    {{ ActiveDirectoryTenantId = zzzzzzzzzzzzzz...