VMware Cloud Community
sravan03ie29
Contributor
Contributor
Jump to solution

How to get ESX host Network Details (IP-Address) Using PowerCLI?

Hi,

I am Using below script to get (ESX hostname, Version,build, Cluster-Name,datacenter, IPaddress (Service console & Vmkernel)

-


Connect-VIServer ********* -User ******** -Password *******

Get-vmhost (Hostname) | Select Name, Version, Build,

@{N="Cluster-Name";E={@(($_ | Get-cluster))}},

@{N="Datacenter";E={Get-Datacenter -VMhost $_}},

@{N="Service-Console";E={@(($_ | Get-vmhostnetworkadapter))}}

-


Output as follows:

-


Name : *******

Version : 3.5.0

Build : 207095

Cluster-Name : *******

Datacenter : *******

Service-Console : {vmnic1, vmnic0, vmnic6, vmnic7...}

-


Can Some please assist me how to modifiy above script to include IPAddress of Service Console & VMkernel .... Thanks in Advance...

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can extend your script with the IP addresses of the VMKernel and Service Console like this:

Get-vmhost (Hostname) | Select Name, Version, Build,
@{N="Cluster-Name";E={@(($_ | Get-cluster))}},
@{N="Datacenter";E={Get-Datacenter -VMhost $_}},
@{N="Service Console";E={@(($_ | Get-vmhostnetworkadapter | Where-Object {$_.PortGroupName -eq "Service Console"}).IP)}},
@{N="VMKernel";E={@(($_ | Get-vmhostnetworkadapter | Where-Object {$_.PortGroupName -eq "VMKernel"}).IP)}}

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
5 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can extend your script with the IP addresses of the VMKernel and Service Console like this:

Get-vmhost (Hostname) | Select Name, Version, Build,
@{N="Cluster-Name";E={@(($_ | Get-cluster))}},
@{N="Datacenter";E={Get-Datacenter -VMhost $_}},
@{N="Service Console";E={@(($_ | Get-vmhostnetworkadapter | Where-Object {$_.PortGroupName -eq "Service Console"}).IP)}},
@{N="VMKernel";E={@(($_ | Get-vmhostnetworkadapter | Where-Object {$_.PortGroupName -eq "VMKernel"}).IP)}}

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
Zsoldier
Expert
Expert
Jump to solution

Using Get-View would probably make this script a whole lot easier.

$NewDataSet = @()
$DataCenters = Get-DataCenter

ForEach ($Datacenter in $DataCenters){
$Clusters = $Datacenter | Get-Cluster

ForEach ($Cluster in $Clusters){
$ClusterHosts = $Cluster | Get-VMHost
$HostView = $ClusterHosts | Get-View

Foreach ($esxhost in $HostView){ 
$NewData = "" | Select Name, Version, Build, Cluster, Datacenter, "Service Console", VMKernel
$NewData.Name = $esxhost.name
$NewData.Version = $esxhost.config.product.version
$NewData.Build = $esxhost.config.product.build
$NewData.Cluster = $Cluster
$NewData.Datacenter = $Datacenter
$NewData."Service Console" = $esxhost.config.network.ConsoleVnic[0].spec.ip.ipaddress
$NewData.VMKernel = $esxhost.config.vmotion.ipconfig.IpAddress
$NewDataSet += $NewData
}
}
}
$NewDataSet

Now granted, I've only tested this on a vSphere 4 environment, but this could give you a good starting point.

Chris Nakagaki (Zsoldier)

http://tech.zsoldier.com

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Although I certainly like the Get-View cmdlet, your script doesn't return information about hosts that are not in a cluster. And there are companies, like the one I work for, that have them.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
Zsoldier
Expert
Expert
Jump to solution

It might be a bit slower, but this would solve that issue:

$NewDataSet = @()
$DataCenters = Get-DataCenter

ForEach ($Datacenter in $DataCenters){
$VMHosts = $null
$VMHosts = Get-VMHost
$HostView = $VMHosts | Get-View

Foreach ($esxhost in $HostView){ 
$NewData = "" | Select Name, Version, Build, Cluster, Datacenter, "Service Console", VMKernel
$NewData.Name = $esxhost.name
$NewData.Version = $esxhost.config.product.version
$NewData.Build = $esxhost.config.product.build
$NewData.Cluster = (Get-Cluster -vmhost $esxhost.name).name
$NewData.Datacenter = $Datacenter
$NewData."Service Console" = $esxhost.config.network.ConsoleVnic[0].spec.ip.ipaddress
$NewData.VMKernel = $esxhost.config.vmotion.ipconfig.IpAddress
$NewDataSet += $NewData
}
}
$NewDataSet

Since the code may take longer to run, placing all that data into a variable becomes even more important since you can just type $NewDataSet within the same powershell window (if running interactively) to output the gathered data more quickly into various different formats.

Chris Nakagaki (Zsoldier)

http://tech.zsoldier.com

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos
sravan03ie29
Contributor
Contributor
Jump to solution

Hi,

Now I got it..Thank you very much for your prompt response..... Smiley Happy

Regards

Sravan Kumar

Reply
0 Kudos