VMware Cloud Community
DDHB
Contributor
Contributor
Jump to solution

Get-view equivalent of commandlets, finding or searching for items in Get-View

Hi all,

I have to be missing something massive here. There has to be a simple way to find a Get-View equivalent of commands like Get-VM, Get-VMHost etc. that provide specific info. 

Here is an example : if you want to get ESXi host license info, you do this:

(Get-VMHost -Name ESX1).LicenseKey

I've looked up and down "Get-View ESX1" output and can't find that same info anywhere (again I might be missing something). How do you map Get-Something output to Get-View output?

Similarly, how does one search for "License" string in Get-View output, going through the entire tree and all objects that are returned by it?

Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The vSphere environment has a number of 'managed services' that handle different types of services, one of those being managing assigned licenses.

One central starting point of these service is located in the ServiceInstance object.

From there you can obtain the assigned license for an ESXi nodes.

$esxName = 'esx1.local.lab'

$si = Get-View ServiceInstance

$licMgr = Get-View -Id $si.Content.LicenseManager

$licAsgnMgr = Get-View -Id $licMgr.LicenseAssignmentManager

$esx = Get-VMHost -Name $esxName

$licAsgnMgr.QueryAssignedLicenses($esx.ExtensionData.MoRef.Value)

You can duplicate all the functionality that is delivered by the PowerCLI cmdlets by using the vSphere API.

Makes you appreciate the work that the PowerCLI Dev Team put in the cmdlets and the properties that these return.


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

The vSphere environment has a number of 'managed services' that handle different types of services, one of those being managing assigned licenses.

One central starting point of these service is located in the ServiceInstance object.

From there you can obtain the assigned license for an ESXi nodes.

$esxName = 'esx1.local.lab'

$si = Get-View ServiceInstance

$licMgr = Get-View -Id $si.Content.LicenseManager

$licAsgnMgr = Get-View -Id $licMgr.LicenseAssignmentManager

$esx = Get-VMHost -Name $esxName

$licAsgnMgr.QueryAssignedLicenses($esx.ExtensionData.MoRef.Value)

You can duplicate all the functionality that is delivered by the PowerCLI cmdlets by using the vSphere API.

Makes you appreciate the work that the PowerCLI Dev Team put in the cmdlets and the properties that these return.


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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

On the 2nd part of your question, all the Get-View properties are available under the ExtensionData property.

(Get-VMHost -Name $esxName).ExtensionData

A handy trick to see what is available in nested objects is to use the Format-Custom cmdlet.

Something like this (notice the Depth parameter)

(Get-VMHost -Name $esxName).ExtensionData | Format-Custom -Depth 2


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

Reply
0 Kudos
DDHB
Contributor
Contributor
Jump to solution

That works, however:

Measure-Command {

     $esx_moref = 'host-2230'

     $si = Get-View ServiceInstance

     $licMgr = Get-View -Id $si.Content.LicenseManager -Property LicenseAssignmentManager

     $licAsgnMgr = Get-View -Id $licMgr.LicenseAssignmentManager

     $licAsgnMgr.QueryAssignedLicenses($esx_MoRef)

}

Gives me 4,261 msecs while

Measure-Command {(Get-VMHost -Name $esx_Name).LicenseKey}

Runs in 2,021, twice as fast. Bear in mind I'm pre-defining MoRefs and names as I already have that info as part of the bigger script and just reuse the values.

I never thought I'd see something that can't be improved with Get-View, I guess there is an exception to everything.

Thanks!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You should probably only compare the fetching of the assigned license key.

The rest is overhead, and most probably done during the connect or on the first retrieval of a HostSystem object.

$licAsgnMgr.QueryAssignedLicenses($esx_MoRef)


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

Reply
0 Kudos