Regular Expression Cheat Sheet

Below is a quick reference guide for regular expressions that I frequently use and find useful.

Online RegEx debugger and library –

How to Adopt Infrastructure as Code by NGINX

Utilising vSphere Performance Monitoring Tools – Part One: ESXTOP

The main use case for using ESXTOP is to retrieve more granular information that that provided in the vSphere Web Client in order to troubleshoot performance issues, and therefore is a better choice that using performance graphs. ESXTOP has as number of modes which are useful in a number of situations:

  • Interactive   – workload is steady and allows for the administrator to examine all the necessary data.
  • Batch – Allows for data to be retrieved in a comma-delimited file to be examined later using a third party tool. This is particularly useful if you want to use another tool to not only examine the data but to also visualize the data.
  • Replay – Allows for the input of data collected using the vm-support command to display data as if this was being produced by the host system.  In combination with batch mode this is useful for workloads that require troubleshooting that provide a particular pattern over a short period of time by allowing data to be retrieved and then examined at a later date and also workloads that need to be monitored over a long period of time.

In this example I will collect data at two second intervals for a duration of two minutes by invoking the vm-support command and saving the output to the datastore named ‘Datastore-01’ in a folder named ‘support’.

1) Browse to the folder to create the output file

cd /vmfs/volumes/Datastore-01/tmp

2) Invoke the vm-support command to retrieve perrformance data (-p) for a period of two minutes (-d 120) at an interval of two seconds (-i) and to save the output file (-w) to the datastore location specified.

vm-support -p -d 120 -i 2 -w /vmmfs/volumes/Datastore-01/support.

3) Now we will browse to the output file and extract the file.

tar -xzf esx-esxi1host.domain.local-2015-01-17--18.06.tgz

4) Once the file has been extracted browse to the contents and execute the reconstruct script.


5) Now we can browse to the parent folder and replay the batch collection.

esxtop -R esx-esxi1host.domain.local-2015-01-17--18.06

ESXTOP allows for the use of custom profiles to save changes to the selections for resource types and fields and to to be able to save these changes to load in the future. In the below example, I will create a custom profile named ‘memswap’ and select to display memory swap statistics only.

1) Press ‘m’ to display memory statistics.

2) Press ‘f’ to display the available memory fields.

3) Select the following fields ‘B’ (GID = Group ID), ‘D’ (Name = Name) and ‘K’ (SWAP STATS = Swap Statistics(MB)) and enter to return to the statistics.

4) Press the ‘W’ key to save the settings into a custom file, in this case ‘memswap’.

5) Press ‘q’ to quit ESXTOP.

Now in order to verify that ESX starts with the custom profile we have created in Steps 1-5, run the following command to start with the custom profile. This step should verify that ESXTOP opens to the swap statistics and only these statistics are displayed.

esxtop -c memswap

It is possible to create multiple custom profiles for use with ESXTOP for monitoring different resource types. Also, you can modify the default ESXTOP profile, while allows for the data displayed by ESXTOP when it is opened to be controlled. In order to make changes to the default profile open ESXTOP without specifying a profile, make changes to the selections as required and then save the (‘W’) the custom profile without specifying a profile, this will write changes to the default profile which is stored at ‘/.esxtop50rc’.

The below is a list of ESXTOP metrics and thresholds for reference taken from Duncan Epping at















2014 in review

The stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 83,000 times in 2014. If it were an exhibit at the Louvre Museum, it would take about 4 days for that many people to see it.

Click here to see the complete report.

PowerCLI: Consolidating virtual machine disks

In order to retrieve a list of virtual machines which are reporting t the issue ‘Virtual machine disks consolidation is needed’ we can invoke the Get-VM cmdlet to determine if a virtual machine consolidation is required.

$VMs = Get-VM | Where-Object {$_.ExtensionData.RunTime.ConsolidationNeeded}

To consolidate snapshots for a collection of virtual machines we can now perform the following, where the virtual machine consolidation will complete before invoking the script block on the next object.

ForEach ($VM in $VMs)

    (Get-VM $VM).ExtensionData.ConsolidateVMDisks()

Encoding image files into a base64 string using Powershell

I was recently looking at encoding image files into a Base64 string to place directly into HTML and CSS, whilst there is a number of useful online tools to complete this task, I decided to have a look at performing this task using Windows Powershell.

This can be achieved by using the [convert]::ToBase64String method and is quite a simple process to retrieve the Base64 string, in  fact a one liner.

By invoking the method agaisnt the content of a file using the Get-Content cmdlet to encodes a set of characters into a sequence of bytes, we retrieve the information we require.

In the below example I am retrieving the Base64 string for the image file D:\Images\image1.jpg

[convert]::ToBase64String((Get-Content D:\Images\image1.jpg -Encoding byte))


VMware Tools Upgrade fails with vix error code 21009

On remediating virtual machines using the Update Manager, a number of VMware Tools upgrades would fail reporting the following:

Error Upgrading VMware Tools
vix error code = 21009

On investigation of vix error codes at there was error code reference for the above. So now it was time to look at the vmware.log file for one of the impacted virtual machines, to which I found the following log entry

TOOLS INSTALL Error copying upgrader binary into guest. success = 0, HgfsStatus = 8

A quick search of the VMware KB, returned the following where the cause of the issue is that the file ‘VMwareToolsUpgrader.exe’ located at ‘C:\Windows\Temp’ only has read-only permissions.

In order to resolve the issue, I removed the file ‘VMwareToolsUpgrader.exe’ from one of the virtual machines returning the error, and attempted to remediate from the attached baseline to which this completed with success.

Therefore, I was required to remove this file from each virtual machine where the file existed, this is where PowerCLI and in particular the Invoke-VMScript cmdlet come in very useful.

Firstly, we will establish a connection to the vCenter system.

If (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) 
    Add-PSSnapin VMware.VimAutomation.Core | Out-Null 

Connect-VIServer server1.domain.local | Out-Null

Now, we build a collection of virtual machines, in this instance we only require those with a Microsoft Windows guest operating system.

$VMs = Get-VM | Where-Object {$_.Guest.OSFullName -like "*Windows*"}

For each virtual machine retrieved in the collection we will perform an operation to create the script text required to remove the file and then pass the variable to the Invoke-VMscript cmdlet. In this instance the script type will be configured to be ‘Bat’ as a number of virtual machines in the collection may not have Windows Powershell installed, the default script type for the Invoke-VMScript cmdlet.

The script text as below will use conditional logic to determine if the ‘VMwareToolsUpgrader.exe’ file exists and delete the file.

IF EXIST C:\WINDOWS\Temp\VMwareToolsUpgrader.exe DEL C:\WINDOWS\Temp\VMwareToolsUpgrader.exe

I also want to produce output of each virtual machine the operation has been performed on and report the exit code, while also ignoring any Warnings generated where the VMware Tools service is no up to date.

ForEach ($VM in $VMs)


        $ScriptText = "IF EXIST C:\WINDOWS\Temp\VMwareToolsUpgrader.exe DEL C:\WINDOWS\Temp\VMwareToolsUpgrader.exe"
        $Script = Invoke-VMScript -ScriptText $ScriptText -VM $VM.Name -ScriptType Bat -WarningAction SilentlyContinue
        "" + $VM.Name + " completed with exit code " + $Script.ExitCode