Step-by-Step: Offline VM Template Servicing in Hyper-V - Part 2 - Downloading Windows Updates via PowerShell

Earlier this month, I published an article here on using PowerShell to perform offline servicing of Windows Updates for a set of VM templates.  After publishing the original article, I received a couple of inquiries for extending that PowerShell script to not only apply Windows Updates to offline VM templates, but to also automate the process of first downloading Windows Updates.  In doing so, this accelerates the process for downloading new updates each month and also reduces the chance of human error in not downloading all needed updates.

software-update

As it turns out, Alexander Krause from Leibniz Universität Hannover in Germany has already done a lot of the “heavy-lifting” for us in automating this process with a PowerShell module that he released on the TechNet Script Center earlier this year.  In this article, I’ll step through the process of using Alexander’s module to automate the downloading of updates for Windows Server 2012 VM templates.

Let’s get started …

To use the Microsoft Updates Downloader PowerShell Module to perform automated downloads of Windows Updates as part of your offline VM template servicing script, you can use these steps:

  1. Download the Microsoft Updates Downloader PowerShell Module from the TechNet Script Center.
     

  2. Since this script is a downloaded module and is not signed, the default PowerShell Execution Policy in Windows Server 2012 R2, which is RemoteSigned, will not permit this script to run.  You can convert this downloaded file to a “local script” that doesn’t require a signature with the default execution policy by running the following command lines:
     
    Set-ExecutionPolicy RemoteSigned # Make sure the default ExecutionPolicy is in effect
    Get-Content MS-UPD-LOAD.psm1 >MS-UPD-LOAD-LOCAL.psm1

     

  3. Now, to download the latest set of updates for Windows Server 2012 VM templates, you can add the following lines to the beginning portion of the script in my original article:
     
    Import-Module MS-UPD-LOAD-LOCAL.psm1

    $updatePath = “D:\Updates”

    Set-Location –Path $updatePath

    Invoke-Update -Year "2013" -Month "12" -ProductFamily "Windows" -Product "Windows Server 2012"

When running the Invoke-Update function above, be sure to change the parameter values to reflect the appropriate Year, Month, ProductFamily and Product values for which you wish to download updates.  Inside the downloaded PowerShell module, you’ll find that Alexander has already documented the standard names for each ProductFamily and Product value for reference purposes.

After the Invoke-Update function completes, you'll find that it built a set of folders inside the folder path specified in the $updatePath variable using the folder structure $updatePath\ProductFamily\Product based on the parameter values specified in the original command line.  Inside the Product folder, you'll find the related MSU and CAB update files, waiting to be applied to your VM templates using the remainder of the script from my original article.

How are you servicing VM templates?

Do you have other approaches that you are using to service and apply updates to your VM templates? If so, please feel free to share your thoughts, ideas and feedback in the Comments area below!