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

PowerShellでWindows Updateを実行する

Last updated at Posted at 2025-10-26

What's?

タイトルどおり、PowerShellでWindows Updateが実行できたらなと思いまして。

PSWindowsUpdate

PSWindowsUpdateというPowerShell Galleryにあるパッケージを使えばよいようです。

PowerShell Galleryというものを知りませんでしたけど。

PSWindowsUpdateはGitHubリポジトリで公開されているようです。

環境

今回の環境はこちらです。

PS > [System.Environment]::OSVersion

Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.22621.0 Microsoft Windows NT 10.0.22621.0


PS > $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      22621  963


PowerShellでWindows Updateを実行する

では、PowerShellでWindows Updateを実行しましょう。

最初にPSWindowsUpdateをインストールします。

PS > Install-Module -Name PSWindowsUpdate -Force -Confirm:$false

初めてInstall-Moduleを使う時は初回はNuGetの確認を求められます。

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
 provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\user\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by
running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y

インストールできたことを確認。

PS > Get-InstalledModule

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
2.2.1.5    PSWindowsUpdate                     PSGallery            This module contain cmdlets to manage Windows Up...


モジュールのインポート。

PS > Import-Module PSWindowsUpdate

PowerShell 3.0以降は明示的に実行しないでもよさそうです。

更新の取得と承認、インストール。必要になった場合は、再起動まで実行されます。

PS > Get-WindowsUpdate -AcceptAll -Install -AutoReboot

単純に更新を確認するだけなら、以下を実行すればOKです。

PS > Get-WindowsUpdate

インストールも行う場合。

PS > Install-WindowsUpdate -AcceptAll -AutoReboot

まとめて。

Install-Module -Name PSWindowsUpdate -Force -Confirm:$false
Import-Module PSWindowsUpdate
Get-WindowsUpdate -AcceptAll -Install -AutoReboot
0
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
0
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?