2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

"Upgrade your Az modules "のメッセージが出た

Last updated at Posted at 2024-09-24

久しぶりにいつも通りのBicep ファイルを使ってデプロイしようとしたところ、次のようなメッセージが表示されました。

WARNING: You're using Az version 11.5.0. The latest version of Az is 12.2.0. Upgrade your Az modules using the following commands:
  Update-PSResource Az -WhatIf    -- Simulate updating your Az modules.
  Update-PSResource Az            -- Update your Az modules.
There will be breaking changes from 11.5.0 to 12.2.0. Open https://go.microsoft.com/fwlink/?linkid=2241373 and check the details.

どうやら昔にインストールしたAZ Powershell のバージョンが更新され、11 系から12 系になっているようです。そしてその間にちょっとしたギャップがあるので自分で確認・更新してね、とのこと。
指示通りに対処してみます。

1. Az をインストール

Install PSResource について調べました。
公式DOCだと、"Install PSResource Az" で最新のモジュール入れられると書いてます。
Update PSResource に関する公式DOC を見ればわかるように、アップデート前にインストールが必要です。
最初のメッセージの"Update PSResource Az -Whatif" コマンドはインストール後、アップデート前に使用するのか!

流れがわかったところでインストールから。公式お墨付きなのでA で進めます。

> Install PSResource Az

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

Update 実行

インストールしたので、Whatif から実行しましたが、なにも返りませんでした。

>  Update-PSResource Az -WhatIf
>

公式を見ても何をするコマンドなのかはよくわからない。

image.png
「コマンドレットの実行時に発生する内容」って、本番Update をかけたときに出るエラーかなんかのことなんですかね。

そのまま本番Update 実行。プロンプトが返るまでは5分くらいでした。

バージョン確認

ちょっと調べて見つけた二つのコマンド、"Get-Module" と"Get-InstalledModule" で混乱したのでメモ。
私の作業環境では、ここまでの作業をした時点で、Az モジュールは"Get-InstalledModule" では確認できず、"Get-Module" では確認できる状況でした。

> Get-InstalledModule -Name Az
Get-Package: No match was found for the specified search criteria and module names 'Az'.

> Get-Module -Name Az -ListAvailable

    Directory: C:\Users\XXX\OneDrive\ドキュメント\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     12.3.0                Az                                  Core,Desk 

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     11.5.0                Az                                  Core,Desk 

二つの違いに関してはこの記事が参考になりました。

さらにcopilot に聞いてみたところ、

Get-InstalledModule:
このコマンドは、PowerShellGet を使用してインストールされたモジュールのみを表示します。
つまり、Install-Module コマンドを使用してインストールされたモジュールが対象です。
Get-Module:
このコマンドは、現在の PowerShell セッションで読み込まれているモジュールを表示します。
また、-ListAvailable オプションを使用すると、システム上のすべてのモジュール(インストール方法に関係なく)を表示します。
したがって、Get-Module で見つかるが Get-InstalledModule で見つからないモジュールは、PowerShellGet 以外の方法でインストールされた可能性があります。例えば、手動でコピーされたモジュールや他のインストール方法を使用したモジュールです。

Install-Module Az をPowerShell で改めてやれば、Get-InstalledModule で見つかりそうですね。
一度、PowerShell を終了してからもう一度立ち上げて、Install-Module -Name Az -force を実行。

> install-Module -name az -force
> Get-installedModule -Name Az

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
12.3.0               Az                                  PSGallery            Microsoft Azure PowerShell - Cmdlets to manage resources in Azur…

よし、これで終了。お疲れさまでした。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?