3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Windows11のPowershellでWindows Updateを実行する

Last updated at Posted at 2022-05-20

GUIのWindows Updateが動かないというトラブル

WIndows Updateの画面でリストがダウンロード待ちになっているけど、「今すぐダウンロード」をクリックしても何の反応もしない。

image.png

PowershellでUpdate

PSWindowsUpdateのインストール

これを使ってPowershellで簡単にWindows Updatgeを行えるようにします。
https://www.powershellgallery.com/packages/PowerShellGet/2.2.5

管理者権限でPowershellを起動し、モジュールをインストールします。

PS C:\Users\admin> Install-Module -Name PSWindowsUpdate
続行するには NuGet プロバイダーが必要です
PowerShellGet で NuGet ベースのリポジトリを操作するには、'2.8.5.201' 以降のバージョンの NuGet
プロバイダーが必要です。NuGet プロバイダーは 'C:\Program Files\PackageManagement\ProviderAssemblies' または
'C:\Users\admin\AppData\Local\PackageManagement\ProviderAssemblies'
に配置する必要があります。'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' を実行して NuGet
プロバイダーをインストールすることもできます。今すぐ PowerShellGet で NuGet
プロバイダーをインストールしてインポートしますか?
[Y] はい(Y)  [N] いいえ(N)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): y

信頼されていないリポジトリ
信頼されていないリポジトリからモジュールをインストールしようとしています。このリポジトリを信頼する場合は、Set-PSReposit
ory コマンドレットを実行して、リポジトリの InstallationPolicy の値を変更してください。'PSGallery'
からモジュールをインストールしますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): a
PS C:\>

途中で実行ポリシーのエラーになる場合は、Set-ExcutionPolicyでポリシーを変更します。

PS C:\Users\admin> Import-Module PSWindowsUpdate
Import-Module : このシステムではスクリプトの実行が無効になっているため、ファイル C:\Program Files\WindowsPowerShell\Mod
ules\PSWindowsUpdate\2.2.0.3\PSWindowsUpdate.psm1 を読み込むことができません。詳細については、「about_Execution_Policie
s」(https://go.microsoft.com/fwlink/?LinkID=135170) を参照してください。
発生場所 行:1 文字:1
+ Import-Module PSWindowsUpdate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : セキュリティ エラー: (: ) [Import-Module]、PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
PS C:\Users\admin> Set-ExecutionPolicy

コマンド パイプライン位置 1 のコマンドレット Set-ExecutionPolicy
次のパラメーターに値を指定してください:
ExecutionPolicy: RemoteSigned
PS C:\Users\admin> Import-Module PSWindowsUpdate
PS C:\Users\admin>

Get-WindowsUpdate

Get-WindowsUpdateでアップデート可能なモジュールのリストを取得する。

PS C:\Users\admin> Get-WindowsUpdate

ComputerName Status     KB          Size Title
------------ ------     --          ---- -----
PC-Name      -------    KB5014329  349MB 2022-05 .NET 5.0.17 Security Update for x64 Client (KB5014329)
PC-Name      -------    KB5014330  435MB 2022-05 .NET 6.0.5 Security Update for x64 Client (KB5014330)
PC-Name      -------    KB5014326  182MB 2022-05 .NET Core 3.1.25 Security Update for x64 Client (KB5014326)
PC-Name      -------    KB890830    39MB 悪意のあるソフトウェアの削除ツール x64 - v5.101 (KB890830)
PC-Name      -------    KB5013628   56MB 2022-05 .NET Framework 3.5 および 4.8 の累積的な更新プログラム (x64 向け Wind…
PC-Name      -------                70MB Windows Admin Center 2110.2
PC-Name      -------    KB5013943  122GB 2022-05 x64 ベース システム用 Windows 11 の累積更新プログラム (KB5013943)

Install-WindowsUpdate

Install-WindowsUpdateで取得したリストのモジュールをダウンロードおよびインストールを行う。

PS C:\Users\admin> Install-WindowsUpdate

Confirm
Are you sure you want to perform this action?
Performing the operation "(xxxx/xx/xx xx:xx:xx) 2022-05 .NET 5.0.17 Security Update for x64 Client (KB5014329)[349MB]"
on target "PC-Name ".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): a

X ComputerName Result     KB          Size Title
- ------------ ------     --          ---- -----
1 PC-Name      Accepted   KB5014329  349MB 2022-05 .NET 5.0.17 Security Update for x64 Client (KB5014329)
1 PC-Name      Accepted   KB5014330  435MB 2022-05 .NET 6.0.5 Security Update for x64 Client (KB5014330)
1 PC-Name      Accepted   KB5014326  182MB 2022-05 .NET Core 3.1.25 Security Update for x64 Client (KB5014326)
1 PC-Name      Accepted   KB890830    39MB 悪意のあるソフトウェアの削除ツール x64 - v5.101 (KB890830)
1 PC-Name      Accepted   KB5013628   56MB 2022-05 .NET Framework 3.5 および 4.8 の累積的な更新プログラム (x64 向け Wi…
1 PC-Name      Accepted               70MB Windows Admin Center 2110.2
1 PC-Name      Accepted   KB5013943  122GB 2022-05 x64 ベース システム用 Windows 11 の累積更新プログラム (KB5013943)
2 PC-Name      Downloaded KB5014329  349MB 2022-05 .NET 5.0.17 Security Update for x64 Client (KB5014329)
2 PC-Name      Downloaded KB5014330  435MB 2022-05 .NET 6.0.5 Security Update for x64 Client (KB5014330)
2 PC-Name      Downloaded KB5014326  182MB 2022-05 .NET Core 3.1.25 Security Update for x64 Client (KB5014326)
2 PC-Name      Downloaded KB890830    39MB 悪意のあるソフトウェアの削除ツール x64 - v5.101 (KB890830)
2 PC-Name      Downloaded KB5013628   56MB 2022-05 .NET Framework 3.5 および 4.8 の累積的な更新プログラム (x64 向け Wi…
2 PC-Name      Downloaded             70MB Windows Admin Center 2110.2
2 PC-Name      Downloaded KB5013943  122GB 2022-05 x64 ベース システム用 Windows 11 の累積更新プログラム (KB5013943)
3 PC-Name      Installed  KB5014329  349MB 2022-05 .NET 5.0.17 Security Update for x64 Client (KB5014329)
3 PC-Name      Installed  KB5014330  435MB 2022-05 .NET 6.0.5 Security Update for x64 Client (KB5014330)
3 PC-Name      Installed  KB5014326  182MB 2022-05 .NET Core 3.1.25 Security Update for x64 Client (KB5014326)
3 PC-Name      Installed  KB890830    39MB 悪意のあるソフトウェアの削除ツール x64 - v5.101 (KB890830)
3 PC-Name      Installed  KB5013628   56MB 2022-05 .NET Framework 3.5 および 4.8 の累積的な更新プログラム (x64 向け Wi…
3 PC-Name      Installed              70MB Windows Admin Center 2110.2
3 PC-Name      Installed  KB5013943  122GB 2022-05 x64 ベース システム用 Windows 11 の累積更新プログラム (KB5013943)
Reboot is required. Do it now? [Y / N] (default is 'N')
               ]y

必要に応じて再起動をするか聞かれるので適宜対応。

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?