Highlighted
Enthusiast
Enthusiast

ESXi Switch details

Hi All,

My Setup is like Management & vMotion are in Distributed Switch , only iSCSI(Storage) is in Standard Switch.

Can someone help me in getting the IP Address, SubnetMask & Gateway of Standard Switch & Distributed Switch in CSV file.

         

vCenter IPESXi HostnameMakeModelService TagESXi IPESXi Subnet MaskESXi GatewayiSCSI IPISCSI Subnet MaskiSCSI Gateway
10 Replies
Highlighted
User Moderator
User Moderator

I suspect this one might give you most of what you are looking for

Re: Need a powershell script for collecting ESX host information


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

Highlighted
Enthusiast
Enthusiast

Hi Lucd,

To be more specific I am looking on Network Label, IP address, subnetmask & gateway of switches configured for ESXi Server.

iSCSI1 IP Address SubnetMask Gateway iSCSI2 IP Address SubnetMask Gateway.

I would need a report as per the configuration. Is there any way that we can get all the details.

pastedImage_0.png

pastedImage_1.png

0 Kudos
Highlighted
User Moderator
User Moderator

So you want to see for each VMKernel that has iSCSI port binding, the IP, subnet and gateway?

Is that correct?


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

0 Kudos
Highlighted
Enthusiast
Enthusiast

Yes Lucd, Including ESXi Mangement & vMotion details along with iSCSI

0 Kudos
Highlighted
User Moderator
User Moderator

Still confused.

Are you looking for VMKernel adapters that are have a binding with the iSCSI HBA?

iscsi.png

Or just VMKernel adapters on your VSS that have a name that starts with iSCSI?


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

0 Kudos
Highlighted
Virtuoso
Virtuoso

Hi, Siva,

Please try the below script if it is suitable to your needs:

$MyOutput = @()

foreach($VMHost in (Get-View -ViewType HostSystem)){

    $netSys = Get-View $VMHost.ConfigManager.NetworkSystem

    $vswTab = @{}

    foreach($vsw in $netSys.NetworkInfo.vSwitch){

        foreach($pnic in $vsw.Pnic){

            $vswTab.Add(($netSys.NetworkInfo.Pnic | where {$_.Key -eq $Pnic}).Device,$vsw.Name)

        }

    }

    foreach ($physnic in $netSys.NetworkInfo.Pnic) {

        $pnicInfo = $netSys.QueryNetworkHint($physnic.Device)

        foreach($hint in $pnicInfo){

            $Report = "" | Select VMHost,vSwitch,vmnic,Status,MAC,Speed,Vlan,PortId,DeviceId,Observed

            $Report.VMHost = $VMHost.Name

            $Report.vmnic = $physnic.Device

            $Report.vSwitch = $vswTab[$physnic.Device]

            $Report.DeviceId = $hint.connectedSwitchPort.DevId

            $Report.PortId = $hint.connectedSwitchPort.PortId

     $Report.Vlan = $hint.connectedSwitchPort.Vlan

     $record = 0

  Do{

     If ($Hint.Device -eq $vmhost.Config.Network.Pnic[$record].Device){

   $Report.Speed = $vmhost.Config.Network.Pnic[$record].LinkSpeed.SpeedMb

   $Report.MAC = $vmhost.Config.Network.Pnic[$record].Mac

     }

     $record ++

  }

  Until ($record -eq ($vmhost.Config.Network.Pnic.Length))

 

  foreach ($obs in $Hint.Subnet){

     $Report.Observed += $obs.IpSubnet + " "

  }

 

   If (($Report.Speed -ge 1000) -and ($Hint.ConnectedSwitchPort.FullDuplex -eq $true)){

   $Report.Status = "OK"

  }Else{If (($Report.Speed -gt 0) -and ($Hint.ConnectedSwitchPort.FullDuplex -eq "")){

   $Report.Status = "CDP not working"

  }ElseIf (($Report.Speed -gt 0) -and ($Hint.ConnectedSwitchPort.FullDuplex -eq $false)){

   if ($Status -ne ""){$Status += " / "}

   $Report.Status = "Duplex config error"

  }ElseIf (($Report.Speed -gt 0) -and ($Report.Speed -lt 1000)){

   if ($Report.Status -ne ""){$Report.Status += " / "}

   $Report.Status = "Speed config error"

  }Else{

   $Report.Status = "Link Down"

  }

  }

        $MyOutput += $Report

}

    }

$MyOutput | Sort VMHost,vSwitch,vmnic | Export-Csv -Path C:\NetworkAudit.csv -NoTypeInformation

}

Let us know how it goes.

/* Any kind of comment or input would be greatly appreciated */
0 Kudos
Highlighted
Enthusiast
Enthusiast

Hi Albert,

Thanks for your script. As per port binding of Management, vMotion & iSCSI, I need a report like below.

          

ESXi IPSubnetGatewayvMotion IPSubnetGatewayiSCSI1 IPSubnetGatewayiSCSI2 IPSubnetGateway
192.168.1.20255.255.255.0192.168.1.1192.168.1.21255.255.255.0192.168.1.1192.168.5.10255.255.255.0192.168.5.1192.168.5.11255.255.255.0192.168.5.1
0 Kudos
Highlighted
VMware Employee
VMware Employee

You can try the below script which is very specific to your described configuration.The

$report = @()
$hosts = Get-VMHost
foreach ($host_name in $hosts)
{
   $gateway = (Get-VMHostNetwork -VMHost $host_name).VMKernelGateway
   $hardware = Get-VMHostHardware -VMHost $host_name
   $adaps =  Get-VMHostNetworkAdapter -VMHost $host_name -VirtualSwitch (Get-VDSwitch) -VMKernel
   $iscsiadap = Get-VMHostNetworkAdapter -VMHost $host_name -VirtualSwitch (Get-virtualswitch -Standard) -VMKernel
   $row = "" | Select "ESXi Hostname", Make, Model, "Service Tag", "ESXi IP", "vMotion IP", "ISCSI IP", Subnet, Gateway
   $row."ESXi Hostname" = $host_name.Name
   $row.Make = $hardware.Manufacturer
   $row.Model = $hardware.Model
   $row."Service Tag" = $hardware.AssetTag
   $row."ESXi IP" = $adaps[0].IP
   $row."vMotion IP" = $adaps[1].IP
   $row."ISCSI IP" = $iscsiadap.IP
   $row.Subnet = $adaps[0].SubnetMask
   $row.Gateway = $gateway
   $report += $row
  

}

$report | Export-Csv "C:\report.csv"

Highlighted
Virtuoso
Virtuoso

Hi, thanks for the follow up in this thread, however, it does not work, see the below result:

Err.JPG

and some of the error message:

Get-VMHostNetworkAdapter : Cannot validate argument on parameter 'VirtualSwitch'. The argument is null. Provide a valid value for the argument, and then try running the command again.

+ ... tworkAdapter -VMHost $host_name -VirtualSwitch (Get-VDSwitch) -VMKern ...

Is this because I do not have dvSwitch ?

/* Any kind of comment or input would be greatly appreciated */
0 Kudos
Highlighted
VMware Employee
VMware Employee

As I have mentioned earlier the script very specific to the environment provided in the question.

Since there is no dvSwitch in your configuration, the script threw an error.

However as you can see in the csv file, all the available network configurations in your en

0 Kudos