How to Update and Patch Nano Server Using PowerShell ?

We can patch nano server with 4 simple steps as we usually do for any general windows server updates.

1) Check for Updates.
2) Install Updates.
3) Restart the server.
4) List all installed updates.

To get the above action completed we need to write PowerShell Script name it as WindowsUpdates_NanoServer.ps1

Login to your Nano Server and copy the below PowerShell script to the server. The script which check for updates and if any updates are require it will install and reboot the server.

######Check for Updates#####
$ci = New-CimInstance -Namespace root/Microsoft/ Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession
$result = $ci | Invoke-CimMethod -MethodName ScanForUpdates -Arguments @{ SearchCriteria=”IsInstalled=0″; OnlineScan=$true}
$result.Updates

##### Install Updates#######

$ci = New-CimInstance -Namespace root/Microsoft/Windows/ WindowsUpdate -ClassName MSFT_WUOperationsSession
Invoke-CimMethod -InputObject $ci -MethodName ApplyApplicableUpdates

##### Restart the Server#####

Restart-Computer; exit

Note : If you receive a disk space error increase VHD size to 4 GB.

Once you login back run the below script to check whether the all the latest updates are installed?

##### List all installed Updates #####
$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession
$result = $ci | Invoke-CimMethod -MethodName ScanForUpdates -Arguments @{ SearchCriteria=”IsInstalled=1″; OnlineScan=$true}
$result.Updates

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s