如何在设备管理器中自动更新所有设备

use*_*121 24 device-manager windows-update drivers windows-10

在 Windows 设备管理器中,可以“手动”启动设备的自动更新。但它非常乏味,必须单击每个设备(因为不知道该特定设备是否有可用更新) - 然后必须单击弹出窗口 - 并且必须等待在线搜索完成。

所以我希望有一些 Powershell 脚本能够做到这一点,或者可能有一个注册表项让“Windows 更新”来处理这个问题。

(嗯,是的,Windows 不会自动更新设备管理器中的所有设备)。

har*_*ymc 19

文章 脚本安装或直接从微软官方更新驱动程序 包含了PowerShell脚本做什么是问。

这篇文章对脚本的每个部分都有很好的解释。我只在下面仅进行了微小更改(我没有测试过)的裸脚本重现:

#search and list all missing Drivers

$Session = New-Object -ComObject Microsoft.Update.Session           
$Searcher = $Session.CreateUpdateSearcher() 

$Searcher.ServiceID = '7971f918-a847-4430-9279-4a52d1efe18d'
$Searcher.SearchScope =  1 # MachineOnly
$Searcher.ServerSelection = 3 # Third Party

$Criteria = "IsInstalled=0 and Type='Driver' and ISHidden=0"
Write-Host('Searching Driver-Updates...') -Fore Green  
$SearchResult = $Searcher.Search($Criteria)          
$Updates = $SearchResult.Updates

#Show available Drivers

$Updates | select Title, DriverModel, DriverVerDate, Driverclass, DriverManufacturer | fl

#Download the Drivers from Microsoft

$UpdatesToDownload = New-Object -Com Microsoft.Update.UpdateColl
$updates | % { $UpdatesToDownload.Add($_) | out-null }
Write-Host('Downloading Drivers...')  -Fore Green  
$UpdateSession = New-Object -Com Microsoft.Update.Session
$Downloader = $UpdateSession.CreateUpdateDownloader()
$Downloader.Updates = $UpdatesToDownload
$Downloader.Download()

#Check if the Drivers are all downloaded and trigger the Installation

$UpdatesToInstall = New-Object -Com Microsoft.Update.UpdateColl
$updates | % { if($_.IsDownloaded) { $UpdatesToInstall.Add($_) | out-null } }

Write-Host('Installing Drivers...')  -Fore Green  
$Installer = $UpdateSession.CreateUpdateInstaller()
$Installer.Updates = $UpdatesToInstall
$InstallationResult = $Installer.Install()
if($InstallationResult.RebootRequired) {  
Write-Host('Reboot required! please reboot now..') -Fore Red  
} else { Write-Host('Done..') -Fore Green }
Run Code Online (Sandbox Code Playgroud)

一个通用且功能强大的软件包是 PSWindowsUpdate

这里有几个关于安装和使用它的教程:

该软件包添加了Get-WUInstall您可以获得和安装更新的命令(和其他命令)。的源Get-WUInstall也可从 github单独 获得

PS 脚本自动化 Windows 和 MS 更新一文中可以找到有关其使用的另一个示例 。

  • 它对我不起作用(`来自 HRESULT 的异常:0x80240024`) (2认同)