Build VM from Template: Interactive PowerCLI Script – VM-Builder-T.ps1


Hi Guys,
In today’s post nothing special πŸ™‚ , I just wanted to share a script I wrote that will build a VM in VMware vSphere environment from a template.
In this post I will detail the workflow and pieces of the code.
At the end of the post, I will place a link to my GitHub repository where you will find the script.
Feel free to read the code and reuse it, if you’re happy with it.

This script contains a full help section that you can invoke by typing the following line:

Get-Help .\VM-Builder-T.ps1 -ShowWindow

As a reminder for those who know my blog πŸ˜‰ this help section is what we call in PowerShell a “Comment-based help”.
I’ve already wrote a post about “Comment-based help” section that you can find here PowerShell Scripts: Help yourself and others. I hope you will enjoy if don’t know about it. πŸ™‚

Ok! Intro is done :-), let’s start the fun part πŸ˜‰


In the VMware environment I work for, we have different teams that interact with vSphere. We have a sysadmin team that is doing regular actions on VMs without having advanced experience with vSphere. Those guys complained about the number of clicks needed to build VM without talking about the vSphere UI that comes slow time to time and so on…
So I decided to write a PowerCLI script that will help them to build VM in a more straight forward way than the GUI and removing potential errors.

The script: VM-Builder-T.ps1


This script is interactive which gives the user a feeling of control on what’s happening. I try to render my scripts interactive especially when I need to deliver them to other teams. The interactivy, I’ve placed in the script permits the user to ingest the data required for the deployment of the VM and check it before running the commands (You know, always better to check twice πŸ™‚ !! )


I think one of the best thing you can do when writing script is to document it by writing down the workflow. It will help you to validate the process and optimize it if needed. In other situations, it will help others to troubleshoot or prepare a new version of the script.
As I like document my work (yes it happens !! πŸ˜‰ ) and I want to render you confident to run it in your environment (if you wish). My best advice, before running it in prod, try to run it in a lab environment, just to be sure it will run as it should in your context… Even if the code is correct, the context can generate issues or failures :-/ (Welcome in IT πŸ™‚ )

So you can find here under the workflow of this script:

script workflow
  • User input is represented by : yellow parallelogram
  • User decision is represented by pink diamond
  • Script action is represented by blue rectangle

The workflow can be divided in 5 steps

script steps explained

Error Handling

To ensure the good processing of the script I’ve tackled error handling in 3 ways:

  • Do…Until loop (permits the user to review and validate his input
  • Try…Catch (permits a clear understanding of a failure in case of a terminating error)
  • Out-Gridview -passThru (prevents typo error by presenting a window to the user by selecting data instead of typing it)

As explained here above, the Out-Gridview -passThru cmdlet will retreive the data from the vCenter instead of having the user of the script typing manually the name of the concerned object.

Here is an example of the code for determining on which ESXi host the VM will be initially placed

Out-gridView cmdlet explained

User Input

To be able to deploy a VM with PowerCLI, you, as a user of the script must have specific data in your hands. Here is the list of components you need before running the script

Mandatory input to ensure the good processing of the script

The data of each component will be stored in variables via the Out-Gridview -Passthru cmdlet


As always, to be able to run the script, your environment /working machine must satisfy some requirements. Here is the list identified in the version 1.0 of the script

Prerequisites for running the script


This script is not a very complicated one but it permits a sysadmin to create easily a VM in a vSphere environment by eleminating potential human errors and vSphere GUI issues.
I hope this post / script will help someone at least by getting ideas to complete his own script.
As mentionned above, feel free to test and use it. As always, run it first in a lab envrionment if you want to use it as is.

It has been tested and validated in a vSphere 6.7 U3 environment. No bug or issue have been reported. The script is in version 1.0, some improvement will come soon. Feel free to check regulary on my github public repository. Don’t hesitate to rate this post as it permits me to have an idea of your degree of sastisfacation of the post. It’s always a source of improvements !! πŸ™‚ πŸ™‚

Link to my script:

Thx to the community !!!

I hope this post helped you,
Dont’ hesitate to comment, like or rate,
Your host,

You can always reach me here:

Install VMware Tools on Windows 2016 Core


In this post I will explain quickly how to install VMware Tools package inside your Windows 2016 Core server VM.

The main point to keep in mind with Windows 2016 Core is that, as the GUI feature is not available, not all installers will work with this version. You need to check with vendor if the software you want to install is compatible with 2016 Core

Regarding VMware, the VM tools installer is fully compatible with the core version of Windows

The procedure:

Note: The procedure here considers that you already mount the VMware tools ISO on your VM via the VMware vSphere Client or VMware workstation GUI.

1)Log on to the guest OS

2) Check that the VMware Tools ISO is mounted to the guest OS by running the Powershell command: Get-volume

3)Identify the drive letter of your Virtual DVD drive (typically the ISO mounted by VMware vSphere Client or VMware Workstation)

4)Navigate to the drive letter of your Virtual DVD (in our case d: ) by typing d: at the prompt

5) Launch the installer by typing the following command in the prompt .\setup.exe and wait for the installer to run as shown in the following screenshot

6) Install the VMware Tools depending on your needs (Typical, Complete, Custom) as shown here under and wait for the installation to finish.

7) At then end of the installation, reboot the VM by selecting yes as detailed in the screenshot here under

8) Check the VMware tools service is running by typing the following command at the prompt: get-service -Name VMTools

You should get the following result …. Ta-Da!!! Enjoy πŸ™‚ πŸ™‚

I hope this post helped you,
Dont’ hesitate to comment, like or rate,
Your host,

You can always reach me here:

My VCP6-DCV Experience

As you probably know, most of IT providers (Microsoft, VMware, Cisco, and many others) that delivers certifications with a limited lifetime. VMware is not an exception.

The main reason invoked everywhere: The rapid change of the technologies put in places.

Recently, I’ve passed my VCP6-DCV as I needed to renew my VCP5-DCV before its expiration. It’s a good way to stay in the train and prove to customers and yourself that you know what you’re talking about.
BUT to achieve this statement,Β you need to prepare yourself seriously, I mean:

  • Read official Study guides
  • Read un-offcial Study guides
  • Read Documentation and books related to the technology
  • Train yourself with the practice exams delivered with the official VMware Study Guide
  • If you don’t have hands-on experience with vSphere 6, build your lab or use VMware Hands-On labs

After passing my exam, I can say you that this exam is not the easiest one. It’s a good mixture of memory questions and practice questions. For some questions, you need to put in practice what you’ve learned from the theory (which are my prefered).

My personal preparation:



  • HomeLab
  • Real-life experience (thanks to my job πŸ™‚ )