Windows Updates/Patches: Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) K |
Admin (Diskussion | Beiträge) |
||
Zeile 1: | Zeile 1: | ||
+ | == Install Windows Update == | ||
+ | ''This works on Windows Server 2016, 2019, 2022 and maybe higher.'' | ||
+ | <source lang="powershell"> | ||
+ | $MSUpdateSearcher = New-Object -ComObject Microsoft.Update.Searcher | ||
+ | $Updates = $MSUpdateSearcher.Search("IsInstalled=0 AND IsHidden=0").Updates | ||
+ | |||
+ | $MSUpdateCollection = New-Object -ComObject Microsoft.Update.UpdateColl | ||
+ | foreach($Update in $Updates) { | ||
+ | $MSUpdateCollection.Add($Update) | Out-Null | ||
+ | } | ||
+ | |||
+ | if($MSUpdateCollection.Count -gt 0) { | ||
+ | Write-Host "Accept EULA, if is necessary." | ||
+ | foreach($Update in $MSUpdateCollection) { | ||
+ | if($Update.EulaAccepted -eq 0) {$Update.AcceptEula()} | ||
+ | } | ||
+ | |||
+ | Write-Host "Download the selected updates." | ||
+ | $MSUpdateSession = New-Object -ComObject Microsoft.Update.Session | ||
+ | $MSUpdateDownloader = $MSUpdateSession.CreateUpdateDownloader() | ||
+ | $MSUpdateDownloader.Updates = $MSUpdateCollection | ||
+ | $MSUpdateDownloader.Download() | ||
+ | |||
+ | Write-Host "Install the downloaded updates." | ||
+ | $MSUpdateInstaller = New-Object -ComObject Microsoft.Update.Installer | ||
+ | $MSUpdateInstaller.Updates = $MSUpdateCollection | ||
+ | $InstallResult = $MSUpdateInstaller.Install() | ||
+ | |||
+ | if ($InstallResult.RebootRequired) { | ||
+ | Restart-Computer -Force | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | |||
+ | |||
== Remove Windows Update == | == Remove Windows Update == | ||
<source lang="powershell"> wusa /uninstall /kb:<KB-Number> </source> | <source lang="powershell"> wusa /uninstall /kb:<KB-Number> </source> |
Version vom 18. Januar 2022, 09:32 Uhr
Install Windows Update
This works on Windows Server 2016, 2019, 2022 and maybe higher.
$MSUpdateSearcher = New-Object -ComObject Microsoft.Update.Searcher $Updates = $MSUpdateSearcher.Search("IsInstalled=0 AND IsHidden=0").Updates $MSUpdateCollection = New-Object -ComObject Microsoft.Update.UpdateColl foreach($Update in $Updates) { $MSUpdateCollection.Add($Update) | Out-Null } if($MSUpdateCollection.Count -gt 0) { Write-Host "Accept EULA, if is necessary." foreach($Update in $MSUpdateCollection) { if($Update.EulaAccepted -eq 0) {$Update.AcceptEula()} } Write-Host "Download the selected updates." $MSUpdateSession = New-Object -ComObject Microsoft.Update.Session $MSUpdateDownloader = $MSUpdateSession.CreateUpdateDownloader() $MSUpdateDownloader.Updates = $MSUpdateCollection $MSUpdateDownloader.Download() Write-Host "Install the downloaded updates." $MSUpdateInstaller = New-Object -ComObject Microsoft.Update.Installer $MSUpdateInstaller.Updates = $MSUpdateCollection $InstallResult = $MSUpdateInstaller.Install() if ($InstallResult.RebootRequired) { Restart-Computer -Force } }
Remove Windows Update
wusa /uninstall /kb:<KB-Number>