在Windows设备管理器中,可以“手动”启动设备的自动更新。但是它非常繁琐,必须单击每个设备(因为不知道该特定设备是否有可用的更新),然后必须单击弹出窗口,并且必须等待在线搜索完成。
因此,我希望有一些Powershell脚本能够做到这一点,或者希望注册表项可以使“ Windows Update”来解决这一问题。
(嗯,Windows不会在设备管理器中自动更新所有设备)。
直接从Microsoft Catalog安装或更新驱动程序的脚本文章包含用于执行所要求操作的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 }
通用且功能强大的软件包是PSWindowsUpdate。
这是有关安装和使用它的一些教程:
该软件包添加了Get-WUInstall
您可以用来获取和安装更新的命令(和其他命令)。的来源Get-WUInstall
也可以从github单独获得。
使用PS脚本自动执行Windows和MS更新的文章中找到了有关其用法的另一个示例。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句