Configuring Nested Hyper-V on ESXi 5.5

In order to allow for installation of a nested Hyper-V on ESXi 5.5, there is a requirement to configure the virtual machine settings once the guest operating system has been deployed.

Firstly, we need to add two items to the existing virtual machine configuration file in a powered off state. Prior to making these changes we will make a backup of the current virtual machine configuration in the event we need to roll back.

cp /vmfs/volumes/<datastore>/<virtual machine>.vmx /vmfs/volumes/<datastore>/<virtual machine>.vmx.backup

In order to  enable nested Virtualization Technology to run 64-bit virtual machines the following is required to added to the configuration file using a text editor.

vhv.enabled = "TRUE"

Now in order to run a hypervisor inside a virtual machine, we will add the following item to override the default setting.  This prevents the error message “Hyper-V cannot be installed: A hypervisor is already running” if you attempt to install the Hyper-V server role in the guest operating system.

hypervisor.cpuid.v0 = "FALSE"

Finally, we need to expose hardware virtualization to the guest operating system so that the processors support the required virtualization capabilities. If you do not expose the hardware virtualization you will receive the error message “The processor does not have the required virtualization capabilities” on installing the Hyper-V server role.

This can be performed using the vSphere Web Client to edit the virtual machine CPU settings as below:




Once , the above configuration changes have been applied to the virtual machine you should be able to install the Hyper-V server role.



Monitor WUInstall status in Nagios XI

I recently wrote about checking the last success time of Windows Update and reporting this to Nagios ( Now what happens if you do not use Windows Update as your patch management solution. In my case I have been managing the installation of updates using WUInstall (

When my updates are installed the registry is not updated to reflect the last success time, therefore how can I monitor the last time updates were run and the status? The command line tool WUInstall provides the functionality to write the console output to a log file, in the below example each log file is written to a shared folder.

As per the previous example, I want to report if any updates have been installed in a particular time-span and if the process was successful.

In the case of the time-span this would be dependent on the host being monitored and therefore this period would be specified as a mandatory parameter when invoking the powershell script which was to be used as the check plugin within Nagios.

Param ([parameter(Mandatory = $true)][string] $Days)

Now I want to return the most recent log file for the host being monitored from the shared folder, where the log file name is that of the host and is contained in a parent folder based on the date the process was invoked. By using the Get-ChildItem cmdlet with the recurse option I am able to retrieve the most recent log file by sorting by the LastWriteTime in descending order and selecting the first file. I will return the full name of the file to a variable to pass to the Get-Content cmdlet for reading.

$LogFile = (Get-ChildItem "\\Server\Share\Logs" -Recurse | Where-Object {$_.Name -like "$env:computername*"} | Sort LastWriteTime -Descending | Select -First 1).FullName

In order to read the content of the log file we will need to encode this in Unicode format, and then search for the string ‘Overall’. In order to retrieve the overall result code we will return the next line from the content and store this as a variable.

$Log = Get-Content $LogFile -Encoding Unicode | Select-String "Overall" -Context 0,1 | % {$_.Context.PostContext}

In order to get the last run time the datetime function will be used to parse the date in the string to return the first ten characters which contain the date and the modify the date string to be in the format ‘dd/MM/yyyy’.

$LastRun = [datetime]::ParseExact($Log.Substring(0,10) , "yyyy/MM/dd", $null)
$LastRun = $LastRun.ToString("dd/MM/yyyy")

Now that we have the last run time and the result code in the log variable we can use conditional logic to set the status of the service. Firstly we will check to see if the last run date is greater or equal to the timespan value specified in the mandatory days field by subtracting this from the current date and if the result code is like ‘Succeeded’ return the service status as ‘OK’

If ($LastRun -ge (get-date).AddDays(-$Days) -and $Log -like "*Succeeded*")
   $resultcode = "0"

If the last run date is less than the time-span value but the result code is like ‘Succeeded’ we will return the service status as ‘OK’.

ElseIf ($LastRun -lt (get-date).AddDays(-$Days) -and $Log -like "*Succeeded*")
   $resultcode = "1"

If the result code is not like ‘Succeeded’ we will return the service status as ‘Critical’.

ElseIf ($Log -notlike "*Succeeded*")
   $resultcode = "2"

If we are unable to retrieve any information required in the conditional logic the service status will be returned as ‘Unknown’.

   $resultcode = "3"

Finally, we will set a status information meessage based on the result code where the substring function is invoked on the  log variable to remove the first twenty characters of the string which contains timestamp information and to include the last run time and terminate the powershell session to return the exit code for the service status.

$Log.Substring(20,$Log.Length-20) + " at " + $LastRun
exit $returncode

Once a check_nrpe command has been configured in Nagios ( and you begin to monitor your host(s), you should see a service check as below:


You can also run the above in Windows Powershell, to return the status information as below:


The full powershell script can be downloaded from: 

Enabling WinRM service using Group Policy

In order to remote manage your remote computers using Windows Powershell, there is a requirement to enable the WinRM service on each target.

This may be enabled by browsing to the below group policy setting path and enabling ‘Allow automatic configuration of listeners:

Computer Configuration/Policies/Administrative Templates/Windows Components/Windows Remote Management (WinRM)/WinRM Service

You may restrict the clients that may connect to the listener by filtering IPv4 and IPv6  addresses, use a wildcard (“*”) to allow all IP addresses or a null value would listen on no IP addresses.

If you have Windows Firewall enabled, you will also need to enable inbound connections for the WinRM Service by enabling TCP service port 5985.

Automating the simulation of random memory workloads using TestLimit utility with Powershell

I was recently looking at simulating memory usage across a number of VMs where the utilisation pattern, time duration of the memory load and idle time between workloads would be random.

I was looking at using the Sysinternals TestLimt utility to achieve this by invoking a leak and touch memory to simulate resource usage.

As I wanted to generate random values I will be using the Get-Random cmdlet to use a value specified in a minimum and maximum range.

One of the requirements of this script is to simulate memory resource usage in a continuous loop, this is achieved by providing the While statement for a condition that is always true.

While ($True)

I will then generate a random values for the duration to run the TestLimit utility and the percentage of memory usage to touch where a minimum and maximum value is specified to the Get-Random cmdlet.

$Date = Get-Date
$Minutes = Get-Random -Minimum 20 -Maximum 120
$Duration = $Date.AddMinutes($Minutes)
$Utilisation = Get-Random -Minimum 20 -Maximum 60

As I specifying memory utilisation as a percentage, I will need to calculate this from the total physical memory configured on the host and truncate to round towards zero. The TestLimit utility requires that memory objects are specified in MB, so the value will be converted following the percentage calculation.

$ComputerSystem = Get-WmiObject Win32_ComputerSystem 
$Memory = [math]::truncate($ComputerSystem.TotalPhysicalMemory /100 * $Utilisasation

Now that I have the values I wish to pass as arguments to the TestLimit utility for the amount of memory to touch and leak, I will start the process, where TestLimit will leak and touch memory pages (-d) with a total amount of memory generated from the above calculation (-c), where the working directory of the utility is ‘C:\TestLimit’.

Start-Process testlimit64.exe -ArgumentList "-d -c $Memory" -workingdirectory "C:\TestLimit"

As I want to run the process only for a period of time specified until the current date is greater or equal to the random duration value generated, the powershell script will be paused using the Start-Sleep cmdlet to check the current date every 60 seconds and to compare that to the duration.

   Start-Sleep -Seconds 60
Until ((Get-Date) -ge $Duration

Once the current date is greater or equal to the duration string the process testlimit64 will be terminated and the script will then be paused for a random period of time generated from the minimum and maximum value. Once the script is resumed, the script block will be invoked again as we want this process to run in a continous loop.

Get-Process | Where-Object {$_.Name -eq "testlimit64"} | Stop-Process
$Sleep = Get-Random -Minimum 180 -Maximum 720
Start-Sleep -Seconds $Sleep 

In this instance the powershell script is invoked by a scheduled task at computer startup. The full script can be downloaded from:

The TestLimit utility can be downloaded from:

Windows Server 2008 R2 Service Pack 1 fails with 800F0818

I was recently attempting to run Windows Server 2008 R2 Service Pack 1, which would fail with the error code 800F0818 due to Windows Update corruption.

In order to resolve the issue, run the System Update Readiness tool and then install the service pack.

The System Update Readiness tool is available from