VMware Cloud Community
MadMax1980
Contributor
Contributor
Jump to solution

vSphere License

Hello,

i tryed to catch License Infos over powershell.

on point i don't know how to query ;(

how is it possible to query which License key is binded to which ESX.

right now i have this code. ( i copied only the contenct from my whole script.)

May somebody could help me outta the space? Smiley Wink

many thx

markus

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Yes, I could reproduce the error. Seems to come from unassigned evaluation licenses.

Try this slightly adapted script.

$showVCLicense = $true

######################
# VMware VC License  #
######################
if ($ShowVCLicense){ 
#	Write-CustomOut "..Adding Licence Infos to the report"

	$LicenseMan = Get-View LicenseManager
	$licAssignMgr = Get-View LicenseAssignmentManager

	$licArr = @()
	foreach($esx in (Get-View -ViewType HostSystem)){
		$assignment = $licAssignMgr.QueryAssignedLicenses($esx.MoRef.Value)
		$assignment | %{
			$row = "" | Select HostName, LicName, LicKey
			$row.HostName = $esx.Name
			$row.LicName = $_.AssignedLicense.Name
			$row.LicKey = $_.AssignedLicense.LicenseKey
			$licArr += $row
		}
	}

	$vSphereLicInfo = @()
	foreach ($License in $LicenseMan.Licenses){
		$Details = "" |Select Name, Key, Total, Used,Information, UsedBy
		$Details.Name= $License.Name
		$Details.Key= $License.LicenseKey
		$Details.Total= $License.Total
		$Details.Used= $License.Used
		$Details.Information= $License.Labels |Select -expand Value
		$hostsAssigned = $licArr | where {$_.LicKey -eq $License.LicenseKey} | %{$_.HostName}
		if(!$hostsAssigned){$hostsAssigned = ""}
		$Details.UsedBy = [string]::Join(",",$hostsAssigned)
		$vSphereLicInfo += $Details
	}
	$vSphereLicInfo
}

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

Sure, try this (note that it requires vSphere 4.x)

$licAssignMgr = Get-View LicenseAssignmentManager
$report = @()

foreach($esx in (Get-View -ViewType HostSystem)){
	$assignment = $licAssignMgr.QueryAssignedLicenses($esx.MoRef.Value)
	$assignment | %{
		$row = "" | Select HostName, LicName, LicKey
		$row.HostName = $esx.Name
		$row.LicName = $_.AssignedLicense.Name
		$row.LicKey = $_.AssignedLicense.LicenseKey
		$report += $row
	}
}
$report

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
MadMax1980
Contributor
Contributor
Jump to solution

Hello Luc,

many thx for your answer.

one question for that.

how could i merge this into my code. so that i also have the (Virtual center license, total,used,...)

many thx

Markus

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, perhaps something like this

$showVCLicense = $true

######################
# VMware VC License  #
######################
if ($ShowVCLicense){ 
#	Write-CustomOut "..Adding Licence Infos to the report"

	$LicenseMan = Get-View LicenseManager
	$licAssignMgr = Get-View LicenseAssignmentManager

	$licArr = @()
	foreach($esx in (Get-View -ViewType HostSystem)){
		$assignment = $licAssignMgr.QueryAssignedLicenses($esx.MoRef.Value)
		$assignment | %{
			$row = "" | Select HostName, LicName, LicKey
			$row.HostName = $esx.Name
			$row.LicName = $_.AssignedLicense.Name
			$row.LicKey = $_.AssignedLicense.LicenseKey
			$licArr += $row
		}
	}

	$vSphereLicInfo = @()
	foreach ($License in $LicenseMan.Licenses){
		$Details = “” |Select Name, Key, Total, Used,Information, UsedBy
		$Details.Name= $License.Name
		$Details.Key= $License.LicenseKey
		$Details.Total= $License.Total
		$Details.Used= $License.Used
		$Details.Information= $License.Labels |Select -expand Value
		$Details.UsedBy = [string]::Join(",",($licArr | where {$_.LicKey -eq $License.LicenseKey} | %{$_.HostName}))
		$vSphereLicInfo += $Details
	}
	$vSphereLicInfo
}

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
MadMax1980
Contributor
Contributor
Jump to solution

Hi theire,

i got a little error at the beginn

Select-Object : Cannot expand property "Value" because it has nothing to expand

Exception calling "Join" with "2" argument(s): "Value cannot be null.

Have many thx

Markus

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, I could reproduce the error. Seems to come from unassigned evaluation licenses.

Try this slightly adapted script.

$showVCLicense = $true

######################
# VMware VC License  #
######################
if ($ShowVCLicense){ 
#	Write-CustomOut "..Adding Licence Infos to the report"

	$LicenseMan = Get-View LicenseManager
	$licAssignMgr = Get-View LicenseAssignmentManager

	$licArr = @()
	foreach($esx in (Get-View -ViewType HostSystem)){
		$assignment = $licAssignMgr.QueryAssignedLicenses($esx.MoRef.Value)
		$assignment | %{
			$row = "" | Select HostName, LicName, LicKey
			$row.HostName = $esx.Name
			$row.LicName = $_.AssignedLicense.Name
			$row.LicKey = $_.AssignedLicense.LicenseKey
			$licArr += $row
		}
	}

	$vSphereLicInfo = @()
	foreach ($License in $LicenseMan.Licenses){
		$Details = "" |Select Name, Key, Total, Used,Information, UsedBy
		$Details.Name= $License.Name
		$Details.Key= $License.LicenseKey
		$Details.Total= $License.Total
		$Details.Used= $License.Used
		$Details.Information= $License.Labels |Select -expand Value
		$hostsAssigned = $licArr | where {$_.LicKey -eq $License.LicenseKey} | %{$_.HostName}
		if(!$hostsAssigned){$hostsAssigned = ""}
		$Details.UsedBy = [string]::Join(",",$hostsAssigned)
		$vSphereLicInfo += $Details
	}
	$vSphereLicInfo
}

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos