Wednesday, July 20, 2016

Automate Update of VM Template - Part 1 - Windows

Automate Update of VM Template - Part 1 - Windows
Automate Update of VM Template - Part 2 - Linux

Update: I've tested and now use this on a Windows Server 2016 VM template as well as 2012 R2.

I don't know about you, but I "love" having to maintain things manually and wasting my time.

Good news is that it only takes 200+ updates and hours of wasted time to patch a fresh installation of Windows Server 2012 R2 server.

One solution we've decided to streamline this task is to maintain a patched virtual machine (VM) template that has the most current Windows updates needed.

"That's a great idea, but you're still having to maintain a VM template." you might say.

Yeah, I don't have to maintain it - my scheduled task that kicks off a PowerCLI/PowerShell script maintains our VM template.

You can find the latest version at: https://github.com/cajeeper/PowerCLI/blob/master/Install-Windows-Update-for-Template.ps1

Here's a breakdown on what this script does:

  • Converts the VM template to a virtual machine
  • Starts the virtual machine
  • Issues PowerShell script block via VMWare Tools to trigger and install any needed Windows updates
  • Sleeps for 10 minutes to allow Windows Updates to reboot the OS as needed
  • Shuts the virtual machine down
  • Converts the virtual machine back to a VM template
  • Logs the results
Optionally:
  • Creates copy of template to another system/site
  • Shows the progress via the CLI
I've been using it for the last few months with success, so I figured its time to share - once again. Note: I've only been testing this on a Windows Server 2012 VM template.

Requirements for the script to function:
  • An existing Windows VM template that has VMware Tools installed and a network adapter to recieve Windows Updates
  • VMware vCenter - Tested on vCenter 6.0.0
  • A user/service account with permissions to Create, Remove, Start, Stop VMs and issue VM scripting commands in vCenter 6.0.0
  • A user/service account with permissions to install Windows Updates in the template virtual machine
  • Update the parameters with all your relevant template, location, etc. and if you want a post copy of the template to kick off.
Here's the last few months of Windows Updates that have been installed on every Fridays for my virtual machine template via this script:
Template Virtual Machine - Windows Update History

Template Virtual Machine - Recent Scripted Tasks and Copy of Template at Dev1 Datacenter
Best of luck!

No comments: