VMware Cloud Community
R0g3r00
Contributor
Contributor
Jump to solution

How to get all VirtualMachineGuestOsIdentifier over PowerCLI

Hi

I would like to get a list of all VirtualMachineGuestOsIdentifier within PowerCLI.

Smth like this:

https://www.vmware.com/support/developer/converter-sdk/conv61_apireference/vim.vm.GuestOsDescriptor....

I tried this:

(get-vm | get-vmguest).GuestID | sort | unique

This Shows all IDs but only from existing VMs, but i want all of it 🙂

I am trying to get the list over the Type "GuestID", but I am not able to do it.

With this line i'm getting the TypeName:

Get-Vm <servername> | get-vmguest | get-member guestid

=> TypeName: VMware.VimAutomation.ViCore.Impl.V1.VM.Guest.VMGuestImpl

Now, I have no idea how to go further from this.

Can you please help me? Or is there a better way?

Thank you very much Smiley Happy

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If you're at least on PowerShell v3, you can do

[VMware.Vim.VirtualMachineGuestOsIdentifier].GetEnumValues()


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

View solution in original post

11 Replies
LucD
Leadership
Leadership
Jump to solution

If you're at least on PowerShell v3, you can do

[VMware.Vim.VirtualMachineGuestOsIdentifier].GetEnumValues()


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

R0g3r00
Contributor
Contributor
Jump to solution

Hi LucD

Thank you very much, exactly what I was looking for Smiley Happy

How did you find out this [VMware.Vim.VirtualMachineGuestOsIdentifier] ?

Is there also a way to get the FullName?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The API Reference and some PowerShell/.Net knowledge.

In a VirtualMachine object, this OS id is stored in the VirtualMachineConfigInfo object under the guestId property.

The API Reference tells me that the property contains a value from the VirtualMachineGuestOsIdentifier‌ enumeration.

guestos.png

In the PowerCLI framework these enumerations are mapped.

From within PowerShell you can get all values for an enumeration with the GetEnumValues method, which is defined on the System.Type since .Net4


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

R0g3r00
Contributor
Contributor
Jump to solution

thank you for the Explanation, I understand now, how it works.

I can see the Property guestFullName from the Object "VirtualMachineConfigInfo".

But this Property does not contain any enumerations, am I right?

Is there another way to get the description for this enumeration VirtualMachineGuestOsIdentifier ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is correct.

The value for guestFullName is obtained via the VMware Tools from within the guest OS.

For vSphere that is just a [string], no enumeration.

Not sure what you mean with that last question ?


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

0 Kudos
R0g3r00
Contributor
Contributor
Jump to solution

I would like to have the VirtualMachineGuestOsIdentifier but also the descripton of the ID within PowerCLI.

As an example, I want this Info: windows7Server64Guest => Windows Server 2008 R2 (64 bit)

And this for each OSIdentifier.

Hope it's clear now

Thx for your time Smiley Happy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid there is no enumeration for that property.

It's a string that comes from within the guest OS, obtained through the VMware Tools.


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

0 Kudos
R0g3r00
Contributor
Contributor
Jump to solution

Ok, what a pity Smiley Sad

Thank you very much for your help

0 Kudos
randomname
Enthusiast
Enthusiast
Jump to solution

$viObjVmHost = Get-VMHost -Name "whatever"

$viewObjEnvBrowser = Get-View -Id (Get-View -Id $viObjVmHost.ExtensionData.Parent).EnvironmentBrowser

$vmxVer = ($viewObjEnvBrowser.QueryConfigOptionDescriptor() | Where-Object {$_.DefaultConfigOption}).Key

$osDesc = $viewObjEnvBrowser.QueryConfigOption($vmxVer,$viObjVmHost.ExtensionData.MoRef).GuestOSDescriptor

Maybe that will give you what you are seeking. It is based on a given host and VM version. I believe it is what gets used by the GUI when deploying a new VM.

R0g3r00
Contributor
Contributor
Jump to solution

Wow, perfect! You are a genius

It works like a charm 🙂

Thank you both for the great support

0 Kudos
rupeshk619
Contributor
Contributor
Jump to solution

Thank you so much, Perfect answer

0 Kudos