Tips for writing Vester test files, part 1

Over the last couple of weeks, I took a look at the Desired State Configuration Resources for VMware (later more on that…).

But above all, I spent quite some time exploring Vester. Vester can be really useful, and it is relatively easy to create additional test files and get more configuration settings under Vester control. While working on new test files, I gathered some lessons learned that can be useful for others.

Naming Test file and the components

Choose a descriptive name for a new test file. Although test files are organized in folders, when the number of test files is increasing descriptive names can be helpful.
What makes a good name? Refer to something that is known and unique.
E.g. For vCenter Clusters, most settings are related to DRS or HA settings, the output of the following command can be helpful:

> Get-Cluster -Name Cluster01 | select *
VsanEnabled               : False
VsanDiskClaimMode         : Manual
HATotalSlots              : 
HAUsedSlots               : 
HAAvailableSlots          : 
HASlotCpuMHz              : 
HASlotMemoryMb            : 
HASlotMemoryGB            : 
HASlotNumVCpus            : 
ParentId                  : Folder-group-h23
ParentFolder              : host
HAEnabled                 : True
HAAdmissionControlEnabled : True
HAFailoverLevel           : 1
HARestartPriority         : Low
HAIsolationResponse       : PowerOff

E.g. Creating a test file for the HA Failover Level, name the test file: “HA-FailoverLevel.Vester.ps1”.
While working on a test file the following variables also play an important role.
The variable $Title is shown during each run of Invoke-Vester and can be used to provide more information then the title of the test file.

Fig. 1

The variable $Desired defines how the test is shown in the Config.json file.
E.g. $Desired = $cfg.cluster.hafailoverlevel, is a Cluster test file and “hafailoverlevel” shows in the Config.json file.

Fig. 2

BTW, you can always add extra comment lines in the test file, e.g. name the valid values for a setting. When there is ambiguity between the PowerCLI output and the vCenter GUI, refer to those settings.
Another example, ESXi hosts do have a lot of Advanced System Settings, the name of these settings is equal in the GUI and in PowerCLI.

E.g. Advanced System Setting “UserVars.ESXIShellInteractiveTimeout”.
– Name the Test file: UserVars-ESXIShellInteractiveTimeout.Vester.ps1
– Variable $Title = ‘UserVars.ESXIShellInteractiveTimeout’
– Variable $Desired = $

Data types

The following data types are supported in a test file:

$Type = ‘string’, defines a single string value. Output in .json file looks like:

"dcuiAccess": "root",

$Type = ‘string[]’ , defines multiple strings. Output looks like:

"esxdns": [

$Type = ‘bool’, defines a boolean value true or false. Output looks like:

"netdumpenabled": "false",

$Type = ‘int’, defines an integer value. Output looks like:

"SecurityAccountUnlockTime": 900,

The test value data type is here to support the conversion in the test files.

Working with ScriptBlocks

If ScriptBlocks are new to you, you may have noticed the following behavior.
You have just created a new test file, finished your $Actual ScriptBlock, run the code and nothing happens.

The solution is simple, just add a “&” before $Actual.

Also don’t forget to assign a value to $Object while testing.
The following ScripBlock will retrieve an advanced setting from host esx01:

$Object = “esx01”

[ScriptBlock]$Actual = {
    (Get-AdvancedSetting -Entity $Object | 
    Where-Object -FilterScript {$_.Name -eq 'UserVars.DcuiTimeOut'}).Value

& $Actual

Use of Get-EsxCli

A number of tests that come with the default installation of Vester make use of the Get-EsxCli cmdlet, which is the PowerCLI version of the esxcli command found on ESXi.
This command underwent a transformation and is now available in a version 2 (parameter -V2), which now is the appropriate way to go.
An excellent reference which describes all the details and how to use the new parameter can be found here on!

In the next part of this post, some of the topics; what to do if there is no Get- and Set- cmdlet to get and set the desired setting, how to test your work and some common errors while creating test files.

You can find my latest test files here.

As always, I thank you for reading and welcome your comments.

And here is Part Two.

This is the second part of a series about configuration drift, Vester and DSC.
Overview of all posts in this series:

About Configuration Drift, Pester and Vester

Tips for writing Vester test files, part 1

Tips for writing Vester test files, part 2

Creating Dashboards for Vester

Vester Test file generator

2 Responses to Tips for writing Vester test files, part 1

  1. James Cruce says:

    I’ve been wanting to start using Vester. Thanks for this post. I will definitely reference this post I start using it.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: