Unattended Windows Update without Configuration Manager


Hello everyone!

I'm back ... it's been a while, right! Yes, I have some hiccups with my job so have to focus on other stuffs.

Even then, I will try to maintain this blog not to let it dies :D

Actually this is an old task but while doing an advance step, I will note this down before we move up to another step.


Use Case:

I have around 40 Windows template VMs in multiple OS languages, they are with Windows 2012, now I have to move all of them to Windows 2012R2 and there is no configuration manager tool like System Center or similar. We manage VM with vCenter and I don't have access to the Administrator panel of vCenter to find if we have any tools for that action so I have to find another way to automate this task with what I have in hands, PowerCLI (from vCenter interface) and my beloved Powershell scripting.

Solution:

I can use PowerCLI to mount the Windows ISO file into the VM's CD drive then the next step should be running the unattended upgrade from Window setup

First of all, you have to mount the CD drive with the ISO file to your VM, PowerCLI will support this very straight forward.

New-CDDrive -VM $targetVm -StartConnected -ISOPath $isoPath -Confirm:$false
Set-CDDrive -CD $cdDrive -IsoPath $isoPath -Connected:$true -StartConnected:$true -Confirm:$false

(*): I have invested a quite time to write a library that support almost the manipulation VM and related objects on vCenter. I will share a generic concept in other post. Those snippet above are copied from the library so you can't copy paste and run but you can get the concept to search from vCenter document for the usage.

Then you have the Windows setup on your machine to run. The next step is to create the unattended xml with your configuration for the upgrade. For the preparation, please read through this page (I don't want to copy and paste what the author already shared) till step 4. Then you should read next to understand how to create your specific configuration and even this page. This is an important part but it might be various due to your need so I can't list out the detail but those pages above already show you the examples.

Next step, we just run the Powershell script on the target VM to copy the unattended.xml to that machine and run the setup.exe from CD drive which point a parameter to the unattended xml as below

Start-Process -FilePath D:\setup.exe -ArgumentList /unattend:C:\UpgradeScripts\Win2012R2_Unattended_Upgrade.xml -Wait

A little bit cheating, although I have tried with -Wait for the installation process however seems it will be disconnected so I have to perform a test to Window Service Manager until it comes back to consider the setup is done. I will wait for 30 minutes (observe the upgrade around that long) and then check for Test-WSMan successfully then we can connect back to the remote VM.

After the setup completed, you will unmount the CD drive from VM then take snapshot (if needed)

$cdDrive = Get-CDDrive -VM $targetVm -Server $server
Set-CDDrive -CD $cdDrive -NoMedia -Confirm:$false
New-Snapshot -VM $targetVm -Name $ssName -Description $ssDescription -Memory:$includeMemory -Quiesce:$isQuiesce -Confirm:$false

Then, you are good! Again, the most complicated is how you create the unattended xml, you will have to spend few hours to understand the "pass" configuration (at least for me :( ) and good luck.

In case you need more detail, leave a comment here or send me an email at truongdinhquang77@gmail.com

Comments

Post a Comment