Checking vmkernel interfaces using get-vmhostnetworkadapter in specific portgroup name

by Grzegorz Kulikowski

If you have labeled vmkernel portgroups using names such as vmotion, nfs that would describe the purpose we can quickly search ip of those cards.
[sourcecode language=”powershell”]
Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost) | ? {$_.PortgroupName -eq "nfs"} | select Name,VMhost,Mac,IP
Name VMHost Mac IP
—- —— — —
vmk1 host1 00:50:56:77:77:77
vmk1 host2 00:50:56:77:77:78
Nice, we now have mac,ip vmkernel interface name and information in which host in the cluster this vmk resides.
Now, if you want to get additional information besides those, you can try to check which are available by yourself.
So the object we are investigating here is a vmhostnetworkadapter.
Let’s take 1 vmhostnetworkadapter first:
[sourcecode language=”powershell”]
Get-VMHost MyHost1 | Get-VMHostNetworkAdapter -VMKernel | ? {$_.PortgroupName -eq "nfs"} | gm
You can see the | gm at the end. This will help us investigate what other properties are available to us.
First we will notice that the object type is:
[sourcecode language=”powershell”]
TypeName: VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.Nic.HostVMKernelVirtualNicImpl
And we will receive whole list of properties and methods that are available
[sourcecode language=”powershell”]
Name MemberType
—- ———-
ConvertToVersion Method
Equals Method
GetHashCode Method
GetType Method
IsConvertableTo Method
ToString Method
AutomaticIPv6 Property
DeviceName Property
DhcpEnabled Property
ExtensionData Property
FaultToleranceLoggingEnabled Property
Id Property
IP Property
IPv6 Property
IPv6Enabled Property
IPv6ThroughDhcp Property
Mac Property
ManagementTrafficEnabled Property
Mtu Property
Name Property
PortGroupName Property
SubnetMask Property
Uid Property
VMHost Property
VMHostId Property
VMHostUid Property
VMotionEnabled Property
If we want to check only properties of this object we could specify this in get-mamber so:
[sourcecode language=”powershell”]
Get-VMHost MyHost1 | Get-VMHostNetworkAdapter -VMKernel | ? {$_.PortgroupName -eq "nfs"} | get-member -MemberType Property
For those who got lost a little with gm … get-member
gm does exactly the same as get-member. If you will type
alias gm
you will receive information that in fact this is just an alias for get-member
[sourcecode language=”powershell”]
CommandType Name Definition
———– —- ———-
Alias gm Get-Member
Alright, back to the main topic.
So what else can we get from the VMHostNetworkAdapter. By now we should see what kind of properties are there. You can add them to the select-object command
[sourcecode language=”powershell”]
Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost) | ? {$_.PortgroupName -eq "nfs"} | select Name,VMhost,Mac,IP ->here
So if you wanted to see for example SubnetMask or Mtu you would just simply add it at the end to select-object like this
[sourcecode language=”powershell”]
Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost) | ? {$_.PortgroupName -eq "nfs"} | select Name,VMhost,Mac,IP,Mtu,SubnetMask
Let’s say we want to see EVERYTHING that is available for us right away:
[sourcecode language=”powershell”]
Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost) | ? {$_.PortgroupName -eq "nfs"} | select *
Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost) | ? {$_.PortgroupName -eq "nfs"} | format-list *
Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost) | ? {$_.PortgroupName -eq "nfs"} | format-table *
As you can see you can query all those properties in different ways.
One more thing, ‘select’ is an alias for Select-Object.
Format-list will generate output in a list as the name suggests 😉
Format-Table will generate a table (you have possibility to configure the table style here)
Select-Object will try to generate a ‘table look’, but it will not be the same table as format-table does. What is worth mentioning here is that for example object that will come from Format-Table or Format-List will not be understood by export-csv. Format-table output looks pretty much the same as if you had used the select-object, but it has different type. In this case only output from select-object could be piped without error to export-csv.
Whenever you are wondering if you can have more information about some object simply use get-member on it. If this will be a VM object, a VMHostNetworkAdapter object or a host object, you always can use get-member to see if there are useful properties for you to check.

You may also like

1 comment July 14, 2014 - 5:32 pm

Natural light is more inviting and gives a soft
mood to the image. Only those real estae agents who are part of tne National Association of
Realtors (NAR) are also considered Realtors;.
Some brokerages will offer structured in-house classes on sales,
lead generation and general business practices.


Leave a Reply

Chinese (Simplified)EnglishFrenchGermanHindiPolishSpanish
Streaming live on Twitch right now.