5
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?

【Windows11】 wingetでPowerShellのアップデートをする

Last updated at Posted at 2024-06-18

バージョンを 5.x.x7.x.x にアップデートする方へ注意
5系で使用できたコマンドの一部が7系では使えなくなってます。
アップデートする際は各自の判断のもとお願いしますorz

概要

新しいPCを購入したら PowerShell 起動時にこんなメッセージが表示されました。

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

新機能と改善のために最新の PowerShell をインストールしてください!https://aka.ms/PSWindows

なので、今回はPowerShellのアップデートを実施しようと思います。

筆者の環境

Windows11

まずは現状のバージョンを確認してみる

僕の環境だと 5.1 が入っていました(PSVersion 参照)

PS C:\Users\hoge> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22621.3672
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.3672
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

最新のPowerShellパッケージを確認する

最新を確認するために、Wingetで配布されている PowerShell パッケージを確認します。

PS C:\Users\hoge> winget search Microsoft.PowerShell
名前               ID                           バージョン ソース
------------------------------------------------------------------
PowerShell         Microsoft.PowerShell         7.4.2.0    winget
PowerShell Preview Microsoft.PowerShell.Preview 7.5.0.3    winget

現在(2024/06/18)だと 7.4.2.0 or 7.5.0.3 が最新版のようです。
7.4.2.0 は LTSリリース、7.5.0.3 は プレビューリリースになります。

最新のPowerShellをインストールする

前章の ID を元に、PowerShell パッケージをインストールします。

PowerShell 7.4.2.0 をインストールする場合

winget install --id Microsoft.Powershell --source winget

PowerShell 7.5.0.3 をインストールする場合

winget install --id Microsoft.Powershell.Preview --source winget

今回は LTS リリースの 7.4.2.0 をインストールします。
「インストールが完了しました」が表示されたらインストール完了です。

PS C:\Users\hoge> winget install --id Microsoft.Powershell --source winget
見つかりました PowerShell [Microsoft.PowerShell] バージョン 7.4.2.0
このアプリケーションは所有者からライセンス供与されます。
Microsoft はサードパーティのパッケージに対して責任を負わず、ライセンスも付与しません。
ダウンロード中 https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/PowerShell-7.4.2-win-x64.msi
  ██████████████████████████████   103 MB /  103 MB
インストーラーハッシュが正常に検証されました
パッケージのインストールを開始しています...
インストールが完了しました

正常にインストールが出来たかの確認

アプリ検索で PowerShell 7系が存在するか確認しましょう。
画面左下の「検索」窓に「PowerShell 7」と入力してください。
image.png

注意
PowerShell のバージョンに応じて、アプリ名が以下のように変わります。

  • 5系:Windows PowerShell
  • 7系:PowerShell 7

念のための確認で、PowerShell 7 を起動して PSVersion を確認します。
PSVersion に「7.4.2」が表示されていれば更新完了です。お疲れさまでした!

PS C:\Users\hoge> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

終わりに

PowerShell 7系にアップデートしたことが無かったので、ちょっとした知見UPになりました。
5系と7系でアプリが違うことを知らず、5系の Windows PowerShell で「バージョンが更新されないんだけど!!」って1時間くらい悩んでました…笑
この記事が少しでもお役に立てればと思います:raised_hands:

5
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
5
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?