1

I have an installation PowerShell script that installs Docker and other components onto Windows Server 2016. I have learned (the hard way) that if the latest Windows Updates are not installed, sometimes Docker will get into a very wierd state and not function as expected.

Therefore, I would like to programmatically check in PowerShell if all available/latest Windows Updates are installed on the server and then show a warning to the user if there are available updates that are not installed.

So the question is, how to programmatically check if all available/latest Windows Updates are installed?

Any help would be greatly appreciated.

3
  • 1
    Look into the power shell module PSWindowsUpdate and Get-Windows Update. Resource: woshub.com/pswindowsupdate-module Sep 19 '20 at 5:53
  • @LukasRäpple Thanks, this is awesome! Do you know of a way to do this without using any third party software/scripts (only built-in Microsoft scripts)?
    – A X
    Sep 19 '20 at 18:35
  • I am not sure that it is possible out of the box. The Module was created by MS MVP, thus, I think you can trust it. You can go through release notes here: gallery.technet.microsoft.com/scriptcenter/…
    – Stuka
    Sep 20 '20 at 23:02
1

I suggest identifying exactly which updates are dependencies for Docker to work properly, and verifying those are installed specifically. It's surprisingly hard to emulate the "Check for Updates" button in PowerShell.

These are the built in commands, but they aren't documented and are just wrappers for WMI method calls.

Get-Command -Module WindowsUpdateProvider

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Get-WUAVersion                                     1.0.0.2    WindowsUpdateProvider
Function        Get-WUIsPendingReboot                              1.0.0.2    WindowsUpdateProvider
Function        Get-WULastInstallationDate                         1.0.0.2    WindowsUpdateProvider
Function        Get-WULastScanSuccessDate                          1.0.0.2    WindowsUpdateProvider
Function        Install-WUUpdates                                  1.0.0.2    WindowsUpdateProvider
Function        Start-WUScan                                       1.0.0.2    WindowsUpdateProvider

Documentation Team issue discussing lack of documentation https://github.com/MicrosoftDocs/windows-powershell-docs/issues/139

PowerShell Team issue discussing the broken functionality https://github.com/PowerShell/PowerShell/issues/5718

This person seems to have figured out how to use the commands. https://richardspowershellblog.wordpress.com/2017/11/17/windows-update-change-in-server-1709/

PS>  $au = Invoke-CimMethod -Namespace root/microsoft/windows/windowsupdate  -ClassName MSFT_WUOperations -MethodName  ScanForUpdates -Arguments @{SearchCriteria="IsInstalled=0"}

PS>  Invoke-CimMethod -Namespace root/microsoft/windows/windowsupdate  -ClassName MSFT_WUOperations -MethodName  InstallUpdates -Arguments @{Updates = $au.Updates}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.