Get the highest concurrent license usage from a VMware Horizon environment

In some managed VMware Horizon environments, I wanted to know the highest concurrent users per month. This information can be found in the Horizon Administrator Console under Settings -> Product Licensing and Usage -> Usage.

Using the VMware Horizon Administrator console is a manual task. I wanted to automate this. To automated this use VMware PowerCLI which supports access to the View API.

To automate retrieve thehighest concurrent users per month perform the following steps:

  • Setup the Horizon PowerCLI module, link
  • The following PowerCLI code display the highest concurrent license usage
Import-Module -Name VMware.VimAutomation.HorizonView
Connect-HVServer -Server <server> -Domain <domain name>

# Clear screen
Clear

# View API
$horapi = $Global:DefaultHVServers.ExtensionData

# Get the highest concurrent licensing usage
$getusage = $horapi.UsageStatistics.UsageStatistics_GetLicensingCounters()
$totalccu = $getusage.HighestUsage.TotalConcurrentConnections
Write-Output " "
Write-Output "The highest concurrent usage count is: $totalccu"

  • To reset the highest concurrent license usage use the following code
# Reset the highest license usage
$horapi.UsageStatistics.UsageStatistics_ResetHighestUsageCount()
$totalccu = $getusage.HighestUsage.TotalConcurrentConnections
Write-Output "The highest usage count is: $totalccu"

By using this code you can create a scheduled task to get the highest concurrent license usage at the end of each month and perform a reset after it for example. So you know what is the highest concurrent license usage is that is connected to the VMware Horizon environment.

Packer has now virtual TPM (vTPM) device support

In an earlier blogpost called “Use Packer to install Windows 11 and enable vTPM and VBS” I highlighted a workaround for adding a virtual TPM (vTPM) device to a VM in a VMware vSphere environment. A vTPM device is needed for running Windows 11 (without using registry hacks to bypass the TPM device check).

The latest Packer Plugin for VMware vSphere (V1.0.3) has now support for adding a vTPM device. Default a vTPM device is not added to the VM deployed with Packer. So if you want to create a Windows 11 Golden Image for example you can use Packer with the VMware vSphere plugin with a vTPM device.

Here are the high over steps outlined to add a vTPM device when provisioning a new VM with Packer.

    • Download Packer 1.7.9  or later (https://www.packer.io/downloads).
    • Add the VMware vSphere plugin to the HCL configuration file (https://github.com/hashicorp/packer-plugin-vsphere)
packer {
  required_version = ">= 0.0.1"
  required_plugins {
    vsphere = {
      version = ">= 0.0.1"
      source  = "github.com/hashicorp/vsphere"
    }
  }
}
  • Add a variable to enable vTPM
variable "vm_tpm" {
  type = string
  default = "true"
}
  • In the vsphere-iso section, add the vTPM configuration parameter that uses the vm_tpm variable to enable the vTPM device (more options can be found here, link)
source "vsphere-iso" "win11basic" {
  vTPM = "${var.vm_tpm}"
}
  • Perform a packer init command to download the Packer plugin binaries define in the config file
    • packer init config.pkr.hcl
  • Run the packer build command to create the VM
    • packer build config.pkr.hcl

The VM will be created with a vTPM device.

With Packer and the VMware vSphere plugin, it is now possible to create a VM with a vTPM device which is needed for deploying Windows 11 VMs. This is a great improvement!

Identify the boot device for a VMware ESXi host

With vSphere 7  VMware is moving away from supporting SD cards and USB as boot media. ESXi Boot configuration with only SD card or USB drive, without any persistent device, is deprecated with vSphere 7 Update 3. In future vSphere releases, it will be an unsupported configuration!

Move from SD cards and USB devices to local persistent disk(s) such as SATA, SAS (including SATADOM), SSD disks as a boot device for example. The minimum disk size is 32 GB, the recommended size is 128 GB. Another option is to use boot from SAN.

More information can be found here link.

The general support period for vSphere 6.7 will end on October 15, 2022. So make sure to upgrade before October 15, 2022, to VMware vSphere 7.

To identify what boot media (does not work for boot from SAN)  is used I created a PowerCLI script that identifies the boot device for every VMware ESXi host in a cluster. After entering the vCenter Server and credentials it will list all the clusters available in the vCenter environment, select the cluster and the boot device per VMWare ESXi host will be identified.

<#
.SYNOPSIS
    This script list the boot device for every VMware ESXi host
.DESCRIPTION
    VMware is moving away from the support of SD cards and USB drives as boot media.
    ESXi Boot configuration with only SD card or USB drive, without any persistent device, is deprecated with vSphere 7 Update 3. 
    In future vSphere releases, it will be an unsupported configuration.
    More information:
    https://blogs.vmware.com/vsphere/2021/09/esxi-7-boot-media-consideration-vmware-technical-guidance.html
.NOTES
    Version:        1.0
    Author:         Ivo Beerens
    Creation Date:  2021 November
    Change:         Creation
#>

# Import the PowerCLI module
Import-Module VMware.PowerCLI

# Variables
$datefile = ( get-date ).ToString('yyyy-MM-dd-hhmmss')
$file = New-Item -type file "C:\Temp\bootdevices$datefile.csv"
$vcenterserver = Read-Host "Enter the vCenter server name"

# Connect to the vCenter Server
Connect-VIServer  $vcenterserver

$cluster = Get-Cluster | Out-GridView -Title "Select the cluster" -OutputMode Single
$allhosts = $cluster | Get-VMHost | where {$_.ConnectionState -eq "Connected"}

$result = @()

foreach ($allhost in $allhosts) {
    $esxcli = Get-EsxCli -V2 -VMHost $allhost
    $result += $esxcli.storage.core.device.list.invoke() | Where {$_.IsBootDevice -match "true"} | Select @{N="Cluster";E={$cluster.Name}},@{N="VMhost";E={$allhost.Name}}, Vendor, Model, IsBootDevice, IsLocal, IsSAS, IsSSD, IsUSB, Device 
}

# Display the output
$result | FT

# Export the output to a CSV file
$result | Export-Csv $file -NoTypeInformation -Force

# Disconnect the vCenter server session 
Disconnect-VIserver -Confirm:$false

The output will be displayed on the screen and saved to a CSV file.

This script makes it easy to identify the boot devices of every VMware ESXi host in a cluster.