Windows Update using PowerShell on Windows 2012 R2 Server

I don’t see there is any build in PowerShell to perform Windows Update on Windows 2012 R2 Server, and after some research, I manage to find the great information on this topic from PowerShell for Windows Update

Please refer to the following PowerShell Script to download the PowerShell Module, extract and install it

#Download the file 
$Destination = "c:\temp\"
$UnzipTo = "c:\temp"

Invoke-WebRequest $Source -OutFile $Destination -Verbose

#Function to unzip the 
function unzip($file, $destination)
 $shell = new-object -com shell.application
 $zip = $shell.NameSpace($file)

 foreach($item in $zip.items())

#Unzip the to CC:\temp to "$env:windir\System32\WindowsPowerShell\v1.0\Modules"
unzip -file $Destination -destination $UnzipTo 

#Copy all the files from PSWindowsUpdate to 
Copy-Item -Recurse $UnzipTo\PSWindowsUpdate -Destination $PSModulePath

#Import the PSWinodwsUpdate Module 
Import-Module PSWindowsUpdate

#Get the Update server 
#Check, Download and Install Update 
#You will need to run this few time to ensure that there is no more update 
Get-WUInstall -Verbose

You will need to run “Get-WUInstall -Verbose” few time to ensure that there is no more update for Windows 2012 R2


I will need to cleanup the downloaded Update in WinSxS folder by using the following commands ( “Desktop Experience” features is required to use the Disk Cleanup in GUI, and since I want to keep my Windows 2012 R2 Server as clean as possible with minimum space). I noticed that it take up 12.5GB of hard disk spaces with only the latest Windows updates installed

#Check how much disk space can be free up 
dism /online /cleanup-image /analyzecomponentstore 
#Clean up WinSxS Folder - it will take some time to complete 
dism /online /cleanup-image /startcomponentcleanup

With the above commands, it will helps to free up some disk spaces