VMware Cloud Community
vwmagic
Enthusiast
Enthusiast
Jump to solution

To list IP's for every vmkernel adapters on every esxi hosts

We have a number of ESXi host in a vCenter, each ESXi host has multiple vmkernel adapters. I am seeking a POWERCLI scripts (not commands on ESXi hosts) to go through all ESXi hosts, and list IP addresses for every vmkernel adapters adapters on each ESXi host. 

I have some knowledge of POWERCLI, but, not so skillful. Please find attached an example.

Can you please help me out?

Labels (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VMHost -PipelineVariable esx |
Get-VMHostNetworkAdapter -VMKernel |
Select-Object @{N = 'VMhost'; E = { $esx.Name } }, Name, IP


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

View solution in original post

Tags (1)
6 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VMHost -PipelineVariable esx |
Get-VMHostNetworkAdapter -VMKernel |
Select-Object @{N = 'VMhost'; E = { $esx.Name } }, Name, IP


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

Tags (1)
LeitaoL
Contributor
Contributor
Jump to solution

Hi LucD, i tried it but not working. Instead, i'm getting this:

PS D:\vSphere> Get-VMHost -PipelineVariable esx | Get-VMHostNetworkAdapter -VMKernel |
Select-Object @{N = 'VMhost'; E = { $esx.Name } }, Name, IP

Get-VMHostNetworkAdapter : 2023-01-31 11:01:14 Get-VMHostNetworkAdapter Value cannot be null.
Parameter name: key
At line:1 char:36
+ ... st -PipelineVariable esx | Get-VMHostNetworkAdapter -VMKernel | Selec ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VMHostNetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVMHost
NetworkAdapter

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Strange, works for me.

Which PowerCLI and Powershell versions are you using?

Get-Module -Name VMware.PowerCLI -ListAvailable
$psversionTable.PSVersion

Did you stop/start your PS session?

 

 


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

LeitaoL
Contributor
Contributor
Jump to solution

Hi LucD and thank you for the swift reply.

PS D:\> Get-Module -Name VMware.PowerCLI -ListAvailable


Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 11.2.0.... VMware.PowerCLI


PS D:\> $psversionTable.PSVersion

Major Minor Build Revision
----- ----- ----- --------
5 1 14409 1018

 

I have already tried a restart of the session, yes.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is a rather old PowerCLI version, you might try to upgrade.

That error has been reported before, see 
Get-VMHostNetworkAdapter -vmkernel = Value cannot... - VMware Technology Network VMTN
Get-VMHostNetworkAdapter not working on some hosts - VMware Technology Network VMTN

but unfortunately no real solution in any of the threads.

If the PowerCLI upgrade doesn't fix it, I'm afraid I would suggest opening an SR


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

LeitaoL
Contributor
Contributor
Jump to solution

Thank you for the help, at least you were able to point me in the right direction!

Reply
0 Kudos