VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

.net objects vs vsphere objects_powercli

Hi Luc,

could you check following and suggest for red color code.

1;i defined one variable using normal powercli command.

$esxi=get-vmhost "vmhost1"

and if i try to find vmkernel adapter i can use folowing and it works fine.

Get-VMHostNetworkAdapter -VMKernel -VMHost $esxi

2:but if i define variableusing get-view

$esxi=get-view -viewtype hostsystem -filter{'name'='vmhost1'} -property name,network

what property i should use to get same info (vmkernel adapter) as in example1.

iam checking following page

vSphere Web Service API - VMware API Explorer - VMware {code}

pastedImage_1.png

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That information sits in the HostVirtualNic object

Try like this

$esxi = Get-View -ViewType HostSystem -Filter @{'Name'='vmhost'} -Property Name,Config.Network.VNic

$esxi.Config.Network.Vnic |

Select Device,Portgroup,@{N='IP';E={$_.Spec.Ip.IpAddress}}


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

View solution in original post

0 Kudos
14 Replies
LucD
Leadership
Leadership
Jump to solution

That information sits in the HostVirtualNic object

Try like this

$esxi = Get-View -ViewType HostSystem -Filter @{'Name'='vmhost'} -Property Name,Config.Network.VNic

$esxi.Config.Network.Vnic |

Select Device,Portgroup,@{N='IP';E={$_.Spec.Ip.IpAddress}}


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks.Just now i was working on one task where in i was not able to search vm using get-vmcommand but able to search using get-view.

could you comment on this.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The Get-View -ViewType VirtualMachine also returns templates.

Could it be a template that you are not seeing with Get-VM?


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

no it was not template but an vba appliance .though there was an alarm but it should not miss from get-vm.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I assume you mean a vApp?

If there is a VM inside that vApp, the VM should be listed with Get-VM and Get-View.


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

it is suse based applinace not vapp.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, but in any case, the VM should be listed with Get-VM and Get-View.

There must be something specific that is causing this discrepancy.

Are you using mete-characters on the Name, or are you using a Filter...


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

i run get-vm vmname    did not give result

i run get-view -viewtype virtualmachine -filter @{'name'='vmname'}   got output

i dont know what  is mete-character.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Meta-characters are * and ?

The explanation for the missing VM could be that 'vmname' is not the exact displayname of the VM.

In that case Get-VM will not return anything.

The Get-View Filter is a RegEx expression, and that will succeed if only part of the name of the matches

Try these two variations

Get-VM -Name *vmname*

Get-View -ViewType VirtualMachine -Filter @{'Name'="^vmname$"}


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

now

Get-VM -Name *vmname*  works

and

Get-View -ViewType VirtualMachine -Filter @{'Name'="^vmname$"}    does not work

however i was able to search in webclientand webclient search by display name only .

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That confirms my suspicion :smileygrin:

With Get-VM I used the meta-character *.

The meaning of *vmname* is that the string 'vmname' can apear anywhere in the displayname of the VM.

So vmname1 will match, and also Myvmname

With Get-View I used the RegEx anchors ^and $, where ^means the beginning of the string and $ means the end of the string.

So in this case only an exact match of vmname will pass through


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks iam checking this.

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

i thought of asking one more question .

while developing powercli scripts with get-view commands do we really need to refer vsphere api documentations .

cant we find all properties and methods by get-member command the way we do in normal powercli comands.

i remeberusing api explorer in orchestator but there we are using java script and hence we need reference.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The Get-Member cmdlet definitely helps, but to get a clear view and explanation of the properties, the API Reference is indispensable imho.


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

0 Kudos