Az PowerShell モジュールのインストールに失敗

f:id:tworks55:20211216002637p:plain

またしてもMicrosoft Learnにてトラブル。 今回は

Azure PowerShell でスクリプトを使用して Azure リソースを作成する - Learn | Microsoft Docs

でAz PowerShell モジュールのインストールに失敗。

PS C:\Windows\System32> Install-Module -Name Az -Scope CurrentUser -Repository PSGallery

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A
Install-Package: The following commands are already available on this
system:'Login-AzAccount,Logout-AzAccount,Resolve-Error,Send-Feedback'. This module 'Az.Accounts' may override the
existing commands. If you still want to install this module 'Az.Accounts', use -AllowClobber parameter.

PS C:\Windows\System32> Connect-AzAccount
Connect-AzAccount: The term 'Connect-AzAccount' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

-AllowClobberオプションをつけて再実行。

PS C:\Windows\System32> Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -AllowClobber

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A

変なエラーが出ていないので無事終了した模様。

Connect-AzAccountコマンドを実行し成功を確認。

PS C:\Windows\System32> Connect-AzAccount

Account                      SubscriptionName TenantId                             Environment
-------                      ---------------- --------                             -----------
xxxxxxxxxxxxxxxxxxx@gmail.com 従量課金         xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx AzureCloud

PS C:\Windows\System32>

ちなみにデバッグモードでインストールするには以下を設定すればよいようです。

$DebugPreference="Continue"

参考URL

Not able to install powershell az module · Issue #9940 · Azure/azure-powershell · GitHub

【Windows/Powershell】「以下のコマンドは、このシステムで既に使用可能になっています」と警告が出る際の注意 - (O+P)ut