First you need to install the PowerShell module.

 # Install-Module -Name PSWindowsUpdate -Force



Then check if there are windows update for your machine.

 # Get-WindowsUpdate



Then if you want to install all the updates you can run the following command. 

 # Get-WindowsUpdate -AcceptAll -Download -Install -MicrosoftUpdate

Now you can reboot the machine with Y

 

With the command Get-WUHistory you can check if the update is installed.

 

# Get-WUHistory

 

 

With the following command you can check the options you can use for the command Get-WindowsUpdate

 

# Get-help Get-WindowsUpdate

 

 

 

PS C:\Users\Administrator> get-help Get-WindowsUpdate

NAME
Get-WindowsUpdate

SYNOPSIS
Get list of available updates meeting the criteria.

SYNTAX
Get-WindowsUpdate [-AcceptAll <SwitchParameter>] [-AutoReboot <SwitchParameter>] [-AutoSelectOnly <SwitchParameter>] [-AutoSelectOnWebSites <SwitchParameter>] [-BrowseOnly <SwitchParameter>] [-Category <string[]>] [-CategoryIDs <string[]>] [-ComputerName <string[]>] [-Criteria <string>] [-Debuger <SwitchParameter>] [-DeploymentAction <string>] [-Download <SwitchParameter>]
[-ForceDownload <SwitchParameter>] [-ForceInstall <SwitchParameter>] [-Hide <SwitchParameter>] [-IgnoreReboot <SwitchParameter>] [-IgnoreRebootRequired <SwitchParameter>] [-IgnoreUserInput <SwitchParameter>] [-Install <SwitchParameter>] [-IsAssigned <SwitchParameter>] [-IsHidden <SwitchParameter>] [-IsInstalled <SwitchParameter>] [-IsPresent <SwitchParameter>] [-KBArticleID
<string[]>] [-MaxSize <long>] [-MinSize <long>] [-NotCategory <string[]>] [-NotKBArticleID <string[]>] [-NotSeverity <string[]>] [-NotTitle <string>] [-NotUpdateID <string[]>] [-PSWUSettings <Hashtable>] [-RecurseCycle <int>] [-RevisionNumber <int>] [-RootCategories <string[]>] [-ScheduleJob <DateTime>] [-ScheduleReboot <DateTime>] [-SendHistory <SwitchParameter>] [-SendRe
port <SwitchParameter>] [-ServiceID <string>] [-Severity <string[]>] [-ShowPreSearchCriteria <SwitchParameter>] [-Title <string>] [-UpdateID <string[]>] [-UpdateType <string>] [-WithHidden <SwitchParameter>] [<CommonParameters>]

Get-WindowsUpdate [-AcceptAll <SwitchParameter>] [-AutoReboot <SwitchParameter>] [-AutoSelectOnly <SwitchParameter>] [-AutoSelectOnWebSites <SwitchParameter>] [-BrowseOnly <SwitchParameter>] [-Category <string[]>] [-CategoryIDs <string[]>] [-ComputerName <string[]>] [-Criteria <string>] [-Debuger <SwitchParameter>] [-DeploymentAction <string>] [-Download <SwitchParameter>]
[-ForceDownload <SwitchParameter>] [-ForceInstall <SwitchParameter>] [-Hide <SwitchParameter>] [-IgnoreReboot <SwitchParameter>] [-IgnoreRebootRequired <SwitchParameter>] [-IgnoreUserInput <SwitchParameter>] [-Install <SwitchParameter>] [-IsAssigned <SwitchParameter>] [-IsHidden <SwitchParameter>] [-IsInstalled <SwitchParameter>] [-IsPresent <SwitchParameter>] [-KBArticleID
<string[]>] [-MaxSize <long>] [-MinSize <long>] [-NotCategory <string[]>] [-NotKBArticleID <string[]>] [-NotSeverity <string[]>] [-NotTitle <string>] [-NotUpdateID <string[]>] [-PSWUSettings <Hashtable>] [-RecurseCycle <int>] [-RevisionNumber <int>] [-RootCategories <string[]>] [-ScheduleJob <DateTime>] [-ScheduleReboot <DateTime>] [-SendHistory <SwitchParameter>] [-SendRe
port <SwitchParameter>] [-Severity <string[]>] [-ShowPreSearchCriteria <SwitchParameter>] [-Title <string>] [-UpdateID <string[]>] [-UpdateType <string>] [-WindowsUpdate <SwitchParameter>] [-WithHidden <SwitchParameter>] [<CommonParameters>]

Get-WindowsUpdate [-AcceptAll <SwitchParameter>] [-AutoReboot <SwitchParameter>] [-AutoSelectOnly <SwitchParameter>] [-AutoSelectOnWebSites <SwitchParameter>] [-BrowseOnly <SwitchParameter>] [-Category <string[]>] [-CategoryIDs <string[]>] [-ComputerName <string[]>] [-Criteria <string>] [-Debuger <SwitchParameter>] [-DeploymentAction <string>] [-Download <SwitchParameter>]
[-ForceDownload <SwitchParameter>] [-ForceInstall <SwitchParameter>] [-Hide <SwitchParameter>] [-IgnoreReboot <SwitchParameter>] [-IgnoreRebootRequired <SwitchParameter>] [-IgnoreUserInput <SwitchParameter>] [-Install <SwitchParameter>] [-IsAssigned <SwitchParameter>] [-IsHidden <SwitchParameter>] [-IsInstalled <SwitchParameter>] [-IsPresent <SwitchParameter>] [-KBArticleID
<string[]>] [-MaxSize <long>] [-MicrosoftUpdate <SwitchParameter>] [-MinSize <long>] [-NotCategory <string[]>] [-NotKBArticleID <string[]>] [-NotSeverity <string[]>] [-NotTitle <string>] [-NotUpdateID <string[]>] [-PSWUSettings <Hashtable>] [-RecurseCycle <int>] [-RevisionNumber <int>] [-RootCategories <string[]>] [-ScheduleJob <DateTime>] [-ScheduleReboot <DateTime>] [-Se
ndHistory <SwitchParameter>] [-SendReport <SwitchParameter>] [-Severity <string[]>] [-ShowPreSearchCriteria <SwitchParameter>] [-Title <string>] [-UpdateID <string[]>] [-UpdateType <string>] [-WithHidden <SwitchParameter>] [<CommonParameters>]

DESCRIPTION
Use Get-WindowsUpdate (aka Get-WUList) cmdlet to get list of available or installed updates meeting specific criteria.

Use Download-WindowsUpdate alias to get list of updates and download it. Equivalent Get-WindowsUpdate -Download.

Use Install-WindowsUpdate (aka Get-WUInstall) alias to get list of updates and install it. Equivalent Get-WindowsUpdate -Install.

Use Hide-WindowsUpdate alias to get list of updates and hide it. Equivalent Get-WindowsUpdate -Hide.

Use Show-WindowsUpdate (aka UnHide-WindowsUpdate) alias to get list of updates and unhide it. Equivalent Get-WindowsUpdate -Hide:$false.

There are two types of filtering update: Pre search criteria, Post search criteria.

– Pre search works on server side, like example: (IsInstalled = 0 and IsHidden = 0 and CategoryIds contains ‘0fa1201d-4330-4fa8-8ae9-b877473b6441’ )

– Post search work on client side after get the pre-filtered list of updates, like example $KBArticleID -match $Update.KBArticleIDs

Status info list:\r\n[A|R]DIMHUB\r\nA-IsAccetped\r\nR-IsRejected\r\n D-IsDownloaded\r\n F-DownloadFailed\r\n ?-IsInvoked\r\n I-IsInstalled\r\n F-InstallFailed\r\n ?-IsInvoked\r\n R-RebootRequired\r\n M-IsMandatory\r\n H-IsHidden\r\n U-IsUninstallable\r\n B-IsBeta

RELATED LINKS
Author Blog https://commandlinegeeks.wordpress.com/

REMARKS
To see the examples, type: “get-help Get-WindowsUpdate -examples”.
For more information, type: “get-help Get-WindowsUpdate -detailed”.
For technical information, type: “get-help Get-WindowsUpdate -full”.
For online help, type: “get-help Get-WindowsUpdate -online”

PS C:\Users\Administrator>