複数の Azure サブスクリプションの管理

警告

AzureRM PowerShell モジュールは、2024 年 2 月 29 日に正式に非推奨になりました。 引き続きサポートを受け、更新を受け取れるようにするために、AzureRM から Az PowerShell モジュールに移行することをお勧めします。

AzureRM モジュールの機能は今後も使用できますが、メンテナンスやサポートは行われないため、引き続きの使用はユーザーの判断に委ねられ、リスクが発生することがあります。 Az モジュールへの移行に関するガイダンスについては、移行リソースを参照してください。

Azure を使い始めたばかりの場合、所有しているサブスクリプションは 1 つだけだと思われます。 しかし、Azure をしばらく利用している場合は、複数の Azure サブスクリプションを作成した可能性があります。 特定のサブスクリプションに対してコマンドを実行するように Azure PowerShell を構成することができます。

  1. アカウント内のすべてのサブスクリプションの一覧を取得します。

    Get-AzureRmSubscription
    
    Environment           : AzureCloud
    Account               : username@contoso.com
    TenantId              : 00000000-0000-0000-0000-000000000000
    SubscriptionId        : 00000000-0000-0000-0000-000000000000
    SubscriptionName      : My Production Subscription
    CurrentStorageAccount :
    
    Environment           : AzureCloud
    Account               : username@contoso.com
    TenantId              : 00000000-0000-0000-0000-000000000000
    SubscriptionId        : 00000000-0000-0000-0000-000000000000
    SubscriptionName      : My DevTest Subscription
    CurrentStorageAccount :
    
    Environment           : AzureCloud
    Account               : username@contoso.com
    TenantId              : 00000000-0000-0000-0000-000000000000
    SubscriptionId        : 00000000-0000-0000-0000-000000000000
    SubscriptionName      : My Demos
    CurrentStorageAccount :
    
  2. 既定のサブスクリプションを設定します。

    Select-AzureRmSubscription -Subscription 'My Demos'
    
  3. Get-AzureRmContext コマンドレットを実行して変更内容を確認します。

    Get-AzureRmContext
    
    Environment           : AzureCloud
    Account               : username@contoso.com
    TenantId              : 00000000-0000-0000-0000-000000000000
    SubscriptionId        : 00000000-0000-0000-0000-000000000000
    SubscriptionName      : My Demos
    CurrentStorageAccount :
    

既定のサブスクリプションを設定すると、すべての Azure PowerShell コマンドが、このサブスクリプションに対して実行されます。