Add-AzureAccountでログイン失敗したときの対処方法

Powershell AzurePowershell

Azureで今はもう新規作成できないクラシックのVirtualNetworkを削除しようと、こちらも古いPowershellコマンドのAdd-AzureAccountでログインしたときに失敗したので、解決方法などを記載します。

広告

Add-AzureAccountでログインが失敗する

アカウントのID/PWと多要素認証のコードを入力したあとに、以下のようなエラーが出てきてログインできませんでした。

PS C:\> Add-AzureAccount
警告: Because the Az modules have all the capabilities of AzureRM modules and more, we will retire the AzureRM modules
on 29 February 2024. Learn more about the migration to Az: http://aka.ms/azpsmigrate.
警告: authentication_canceled: User canceled authentication
Add-AzureAccount : No subscriptions are associated with the logged in account in Azure Service Management (RDFE). This
means that the logged in user is not an administrator or co-administrator for any account.\r\nDid you mean to execute C
onnect-AzureRmAccount?
発生場所 行:1 文字:1
+ Add-AzureAccount
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Add-AzureAccount]、ArgumentException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount

エラーの内容を日本語にすると
ログインアカウントにサブスクリプションが関連付けられていません
という内容になっていて、全然意味が分かりませんでした。

原因:レガシの権限を付与する必要があった

原因は該当のサブスクリプションに対して サービス管理者 もしくは、共同管理者 という権限がログインアカウントに無かったからでした。

これらの権限は一昔前にあった 所有者 や 共同作成者 というようなレガシの権限で、Azureポータルから追加が可能でした。

以下のようにサブスクリプションの画面を開き[アクセス制御(IAM)] > [従来の管理者] から今の設定を確認することができます。

レガシ権限の確認方法

また、権限を追加する際には上記のキャプチャの緑色の箇所を押すと、[共同管理者の追加] という画面が出てくるのでここでアカウントを追加できます。

共同管理者権限の追加方法

今回はこの手順で[共同管理者]権限を追加することで以下のようにログインできました。

PS C:\> Add-AzureAccount
警告: Because the Az modules have all the capabilities of AzureRM modules and more, we will retire the AzureRM modules
on 29 February 2024. Learn more about the migration to Az: http://aka.ms/azpsmigrate.

Id                                Type Subscriptions                        Tenants
--                                ---- -------------                        -------
hogeuser@hogehoge.onmicrosoft.com User xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}


PS C:\>

[参考] Azure PowerShell Service Management モジュールのインストール方法

AzurePowershellのモジュールのインストール方法は、以下のMicrosoftの公式ドキュメントを利用しました。

Azure PowerShell Service Management モジュールのインストールと構成 | Microsoft Learn

コメント

タイトルとURLをコピーしました