forked from farag2/Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Download_Install_Updates_for_Drivers.ps1
53 lines (42 loc) · 1.57 KB
/
Download_Install_Updates_for_Drivers.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$Searcher.ServiceID = "7971f918-a847-4430-9279-4a52d1efe18d"
# MachineOnly
$Searcher.SearchScope = 1
# Third Party
$Searcher.ServerSelection = 3
Write-Verbose -Message "Searching Driver Updates..." -Verbose
$SearchResult = $Searcher.Search("IsInstalled=0 and Type='Driver' and IsHidden=0")
$Updates = $SearchResult.Updates
#Show available Drivers
$Updates | Select-Object -Property Title, DriverModel, DriverVerDate, Driverclass, DriverManufacturer
#Download the Drivers from Microsoft
$UpdatesToDownload = New-Object -Com Microsoft.Update.UpdateColl
$Updates | ForEach-Object -Process {
$UpdatesToDownload.Add($_) | Out-Null
}
Write-Verbose -Message "Downloading Drivers..." -Verbose
$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 | ForEach-Object -Process {
if ($_.IsDownloaded)
{
$UpdatesToInstall.Add($_) | Out-Null
}
}
Write-Verbose -Message "Installing Drivers..." -Verbose
$Installer = $UpdateSession.CreateUpdateInstaller()
$Installer.Updates = $UpdatesToInstall
$InstallationResult = $Installer.Install()
if ($InstallationResult.RebootRequired)
{
Write-Verbose -Message "Reboot required" -Verbose
}
else
{
Write-Verbose -Message "Done" -Verbose
}