Aug 202008
VI Toolkit Product Manager Carter Shanklin pointed out in the VMware Communities that the script I posted yesterday can be significantly shortened. They have intrduced the shortcut:
Get-View ServiceInstance
So the script I posted yesterday can be reduced to:
$SI = Get-View ServiceInstance
$LicMan = Get-View $SI.Content.LicenseManager
$LicMan.Source.LicenseServer
Here’s another one for you to explore:
$OM = Get-View $SI.Content.Setting
$OM.Setting
…et voilà: SNMP and SMTP settings at your fingertips.
Enjoy!
Related posts:

[...] showed you
Now that is useful, I was wondering how to find out information about the license server, great post.
Hi Hugo,
love the PowerShell scripts so far, keep them coming! I would like to add a License Server query to your “Custom Fields” script, so that I can show if each host is correctly connected to our License Server.
I have been looking at the “LicenseState”:
http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.LicenseManager.LicenseState.html
Is this even possible with this different Managed Object Type? If so where am I going wrong (here’s the relevant code)?
$ManagedObjectType = “LicenseManager”
…
ForEach ($VMHostView in $VMHostViews)
{
$License = $VMHostView.Content.LicenseManagerState
# Compare value to current value
If ($License -ne ($VMView.CustomValue | ?{$_.Key -eq $myCustomField.Key}).Value)
{
# Set Custom Value
$VMHostView.setCustomValue($CustomFieldName,$License)
}
}
Any help appreciated, Forbes.
@Forbes Guthrie
Hi Forbes,
Thanks!
Just leave $ManagedObjectType = “HostSystem”
This variable is only used to define to which object the custom field should be attached.
Hugo
@admin
Hi Hugo,
I’ve tried it with both, but no luck. I can run this against VC, but all it gives is the license server of VC itself. I would like to run this (or something similar) against each host (I’m have an ongoing license issue with several hosts which I need to monitor). Can you spot anything wrong with this:
. “C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts\Initialize-VIToolkitEnvironment.ps1″
# Variables
$VCServerName = “VCSERVER”
$CustomFieldName = “LicenseState”
$ManagedObjectType = “HostSystem”
# Script
$VC = Connect-VIServer $VCServerName
$SI = Get-View ServiceInstance
$CFM = Get-View $SI.Content.CustomFieldsManager
$myCustomField = $CFM.Field | Where {$_.Name -eq $CustomFieldName}
If (!$myCustomField)
{
# Create Custom Field
$FieldCopy = $CFM.Field[0]
$CFM.AddCustomFieldDef($CustomFieldName,$ManagedObjectType,$FieldCopy.FieldDefPrivileges,$FieldCopy.FieldInstancePrivileges)
}
# Fill Custom Fields
$VMHosts = Get-VMHost
$VMHostViews = $VMHosts | Get-View
ForEach ($VMHostView in $VMHostViews)
{
$LicenseState = $VMHostView.Content.LicenseManagerState
# Compare value to current value
If ($LicenseState -ne ($VMView.CustomValue | ?{$_.Key -eq $myCustomField.Key}).Value)
{
# Set Custom Value
$VMHostView.setCustomValue($CustomFieldName,$LicenseState)
}
}
Disconnect-VIServer -Confirm:$False
Many thanks, Forbes.
@Forbes Guthrie
Then the issue us in this line:
$LicenseState = $VMHostView.Content.LicenseManagerState
This apparently retrieves the VC Licence State, not the ESX Server Licence State.
I’ll take a look if I can find the proper field.
Hugo
That’s great, thanks for your effort.
[...] have showed you before how to access the License Manager with the Powershell VMware VI Toolkit. But the properties of the [...]
Forbes,
I have done some investigation and created a new post on how to do this:
http://www.peetersonline.nl/index.php/vmware/getting-detailed-vmware-license-information-with-powershell/
Hope that helps!
Hugo
Fantastic, thank you Hugo. I’ll let you know how it goes.