VMware Cloud Community
damiankarlson
Enthusiast
Enthusiast

Refresh vSphere client GUI with MOB info

With help from some posts from LucD, I've written a PowerCLI script that sets a license key on a specified host. I can invoke the QueryAssignedLicenses method from the MOB, but the licensing information in the vSphere client doesn't change immediately. Does anyone know how to refresh the hosts' licensing page to match the newly updated values in the MOB?

Twitter: @sixfootdad Blog: damiankarlson.com Podcast: professionalvmware.com/brownbags
Reply
0 Kudos
2 Replies
damiankarlson
Enthusiast
Enthusiast

Perhaps I need to clarify. First, some code.

$vcenter = Connect-VIServer vcenterserver.domain.com -Protocol https
$servInst = Get-View ServiceInstance
$licMgr = Get-View $servInst.Content.licenseManager
$licAssignMgr = Get-View $licMgr.licenseAssignmentManager

function Get-LicenseKey($LicName)
{
	$licenses = $licMgr.Licenses | where {$_.Name -eq $LicName}
	foreach ($license in $licenses) {
			if ( ($license.Total - $license.Used) -ne "0") {
				return $license.LicenseKey
				break
			}
	}
}
function Get-VMHostUuid($Name)
{
	$vmhost = Get-VMHost $Name | Get-View
	return $vmhost.Summary.Hardware.Uuid
}
function Set-LicenseKey($VMHostUuid, $LicKey, $Name)
{
	$license = New-Object VMware.Vim.LicenseManagerLicenseInfo
	$license.LicenseKey = $LicKey
	$licAssignMgr.UpdateAssignedLicense($VMHostUuid, $license.LicenseKey, $Name)
}
$LicKey = Get-LicenseKey -LicName "vSphere 4 Enterprise"
$VMHostUuid = Get-VMHostUuid -Name esxhost.domain.com
Set-LicenseKey -LicKey $LicKey -VMHostUuid $VMHostUuid -Name esxhost.domain.com

I can set an available vSphere 4 Enterprise license key on a specific host's UUID, and can verify the results by invoking the QueryAssignedLicenses method on the MOB. I can also set a vSphere 4 Standard license key on that same UUID, and verify the results.

However, no matter what I set thru the API, vCenter only reflects what was set thru vCenter. If I make a license version change in vCenter, the change isn't reflected in the MOB.

My question is -- what am I doing wrong? How can I get the MOB and vCenter to match up, one way or the other?

Twitter: @sixfootdad Blog: damiankarlson.com Podcast: professionalvmware.com/brownbags
Reply
0 Kudos
damiankarlson
Enthusiast
Enthusiast

Woohoo!! Figured it out. Here's the revised code.

$vcenter = Connect-VIServer vcenterserver.domain.com -Protocol https
$servInst = Get-View ServiceInstance
$licMgr = Get-View $servInst.Content.licenseManager
$licAssignMgr = Get-View $licMgr.licenseAssignmentManager

function Get-LicenseKey($LicName)
{
	$licenses = $licMgr.Licenses | where {$_.Name -eq $LicName}
	foreach ($license in $licenses) {
			if ( ($license.Total - $license.Used) -ne "0") {
				return $license.LicenseKey
				break
			}
	}
}
function Get-VMHostId($Name)
{
	$vmhost = Get-VMHost $Name | Get-View
	return $vmhost.Config.Host.Value
}
function Set-LicenseKey($VMHostId, $LicKey, $Name)
{
	$license = New-Object VMware.Vim.LicenseManagerLicenseInfo
	$license.LicenseKey = $LicKey
	$licAssignMgr.UpdateAssignedLicense($VMHostId, $license.LicenseKey, $Name)
}
$LicKey = Get-LicenseKey -LicName "vSphere 4 Standard"
$VMHostId = Get-VMHostId -Name esxhost.domain.com
Set-LicenseKey -LicKey $LicKey -VMHostId $VMHostId -Name $null

The difference is that you must retrieve the Managed Object ID for the HostSystem, rather than the hardware UUID, which is where I was going wrong previously. Big props to Onyx, by setting the license in vCenter thru Onyx, I was able to see the error of my ways.

Twitter: @sixfootdad Blog: damiankarlson.com Podcast: professionalvmware.com/brownbags
Reply
0 Kudos