Getting detailed VMware license information with Powershell

I have showed you before how to access the License Manager with the Powershell VMware VI Toolkit. But the properties of the License Manager appear to only reflect the Virtual Center License Information. So how do we get information about licensing for each individual ESX Server?
We need to take a look at the methods of the License Manager.
First, we connect to the License Manager:

$SI = Get-View ServiceInstance
$LM = Get-View $SI.Content.LicenseManager

Examine the methods of the License Manager:

$LM | Get-Member -MemberType method
methods

Lets see how the QueryLicenseUsage method works:

$LM.QueryLicenseUsage
methoddef

It requires one parameter host of type ManagedObjectReference. So we need a reference to a VMHost:

$VMHostView = Get-VMHost “NAME” | Get-View

$VMHostRef = $VMHostView.MoRef

Now we can call the method:

$LicUse = $LM.QueryLicenseUsage($VMHostRef)

Useful information includes:

$LicUse.Source.LicenseServer   # Contains the license server name and port

$LicUse.ReservationInfo   # Contains license information for each feature available
reservationinfo

To find more information about each feature, take a look at the FeatureInfo property of the License Manager:

$LM.FeatureInfo

featureinfo

Now, you can take the info you need and use it in your scripts.

Enjoy!

Hugo

»crosslinked«

Changing your VMware license server

Hi everybody, I’m back!

Before you ask, I’ve had a great holiday, thank you. Now let’s continue having fun with Powershell and the VI Toolkit!

I’ve showed you a trick earlier that allows you to find your Virtual Center Server Settings. The License Server settings for instance. But changing these settings can prove to be quite a challenge. Let’s take a look:

$SI = Get-View ServiceInstance
$LicMan = Get-View $SI.Content.LicenseManager

This is the way we connected to the License Manager. Get-Member shows us that the $LicMan variable has a method called ConfigureLicenseSource. This method required two parameters: first a reference to the ESX server and second an object with the new license server settings.

The “managed object reference” to the ESX server took some time to figure out, but it’s actually quite easy:

$ESXServerName = “ESXSERVER01”
$VMHost = Get-VMHost $ESXServerName
$hostref = ($VMHost | Get-View).MoRef

By now, you should know how to use Get-View a bit. The resulting object has a MoRef property which can be used in the ConfigureLicenseSource method.

The object containing the new license settings was also a bit of a puzzle. The method shows it wants an object of type “LicenseSource”. But after consulting the VMware Infrastructure API Reference, I found this type of object has no properties! Then how to set the license server name and port?
More searching yielded a different type of object “LicenseServerSource”. This object type has a property called LicenseServer, which accepts a string as input. This object extends the LicenseSource object (according to the API Reference) and it turns out you can use it in the method:

$LicServer = “27000@LicenseServer.domain.local”
$licsrc = New-Object VMware.Vim.LicenseServerSource
$licsrc.LicenseServer = $LicServer

Now we have all the info we need, and we can execute the method:

$LicMan.ConfigureLicenseSource($hostref,$licsrc)

Enjoy!

Virtual Center Server Settings revealed by Powershell

I’ve got a powerfull snippet of code for you today! Sure, we’ve already had lot’s of fun using the VI Toolkit to find and manipulate all sort of settings. But do you know where to find the Virtual Center Server settings, which you access in the VI Client through the menu Administration -> VirtualCenter Management Server Configuration? You soon will!
Here’s an example that grabs the License Server setting for you:

$svcRef = new-object VMware.Vim.ManagedObjectReference
$svcRef.Type = “ServiceInstance”
$svcRef.Value = “ServiceInstance”
$serviceInstance = get-view $svcRef
$licRef = $serviceInstance.Content.LicenseManager
$LicMan = Get-View $licRef
$LicMan.Source.LicenseServer

Explore the $serviceInstance.Content property to get an idea for the other things you can access using this “trick”:

RootFolder
PropertyCollector
ViewManager
About
Setting
UserDirectory
SessionManager
AuthorizationManager
PerfManager
ScheduledTaskManager
AlarmManager
EventManager
TaskManager
ExtensionManager
CustomizationSpecManager
CustomFieldsManager
AccountManager
DiagnosticManager
LicenseManager
SearchIndex
FileManager
VirtualDiskManager
VirtualizationManager

Imagine all the possibilities! You can expect more useful scripts from me in the days to come, so stay tuned!