PeetersOnline.nl
Virtual Center Server Settings revealed by Powershell (2)
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!
10 Responses to Virtual Center Server Settings revealed by Powershell (2)
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





[...] 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.
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
[...] have showed you before how to access the License Manager with the Powershell VMware VI Toolkit. But the properties of the [...]
Fantastic, thank you Hugo. I’ll let you know how it goes.