Bobcares

Updating Windows VM Templates on VMWare with PowerShell

by | Apr 6, 2021

Updating Windows VM Templates on VMWare is quite essential in order to deploy new virtual machines in VMWare. It is necessary to keep it up-to-date at least once a month.

Here at Bobcares, we have seen several such Windows-related queries as part of our Server Management Services for web hosts and online service providers.

Today we’ll see how to update Windows VM Templates on VMWare with PowerShell.

 

Updating Windows VM Templates on VMWare

Now let’s take a look at how our Support Engineers update the Windows VM templates on VMWare.

The update process comprises the following steps.

  1. Converting a template from the Content Library to a virtual machine.;
  2. An administrator logs on after starting it and installs approved Windows updates using WSUS. Then he updates the required software;
  3. After installing the updates, the VM is restarted, then turned off and converted back to the template.

Now we shall how to install Windows updates to a VMWare virtual machine template automatically without doing anything manually.

We can make use of PowerCLI to install updates to a Windows virtual machine. Here we are considering that the PowerShell version 4 (or newer), and the PSWindowsUpdate module are installed in the virtual machine template. Running PowerShell scripts must be allowed in the guest OS by the script execution policy.

We make use of the below PowerCLI script to automatically convert a VMWare template into a VM and install security updates from WSUS:

# Import the PowerCLI module
Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue
# Connect to vCenter
connect-viserver de-vcenter1
$TeplateVMName="Win2016StdTemplate"
# Convert a template to a VM
Set-Template -Template $TeplateVMName -ToVM -Confirm:$false –RunAsync
# Make a 60 seconds delay
Start-sleep -s 60
# Start the virtual machine
Start-VM -VM $TeplateVMName | Get-VMQuestion | Set-VMQuestion -DefaultOption -Confirm:$false
Start-sleep -s 120
# Get an administrator credentials from an encrypted file (if you do not want to keep the password in the PS script in clear text)
$adminname = "administrator"
$Pwd = Get-Content c:\Scripts\VMWare\vm_admin_passfile.txt | ConvertTo-SecureString $
cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $adminname, $Pwd
# Run the command to install all available updates in the guest OS using VMWare Tools (the update installation log is saved to a file: C:\temp\Update.log)
Invoke-VMScript -ScriptType PowerShell -ScriptText "Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot" -VM $TeplateVMName -GuestCredential $Cred | Out-file -Filepath C:\temp\Update.log -Append
Start-sleep -s 1800
# Update VMTools version
Update-Tools -VM $TeplateVMName -NoReboot
# Clean up the WinSxS component store and optimize the image with DISM
Invoke-VMScript -ScriptType PowerShell -ScriptText "Dism.exe /Online /Cleanup-Image /StartComponentCleanup /ResetBase" -VM $TeplateVMName -GuestCredential $Cred
Start-sleep -s 1800
# Force restart the VM
Restart-VMGuest -VM $TeplateVMName -Confirm:$false
# Shut the VM down and convert it back to the template
Shutdown-VMGuest –VM $TeplateVMName -Confirm:$false –RunAsync
Start-sleep -s 180
Set-VM –VM $TeplateVMName -ToTemplate -Confirm:$false

Also, we can add this PowerShell script to the Task Scheduler to automatically install updates to the template once a month. Then if you deploy a new virtual machine from a VMWare template, you may be sure that the latest Microsoft security updates are installed in it.

[Still not able to update Windows VM Templates on VMWare? – We are here to help you]

 

Conclusion

Today, we saw how our Support Engineers update Windows VM Templates on VMWare.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF