Automation

 View Only
Expand all | Collapse all

ESXi Switch details

  • 1.  ESXi Switch details

    Posted Oct 05, 2017 12:34 PM

    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


  • 2.  RE: ESXi Switch details

    Posted Oct 05, 2017 12:44 PM

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

    Re: Need a powershell script for collecting ESX host information


  • 3.  RE: ESXi Switch details

    Posted Oct 05, 2017 01:21 PM

    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.



  • 4.  RE: ESXi Switch details

    Posted Oct 05, 2017 01:28 PM

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

    Is that correct?



  • 5.  RE: ESXi Switch details

    Posted Oct 05, 2017 02:31 PM

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



  • 6.  RE: ESXi Switch details

    Posted Oct 05, 2017 04:06 PM

    Still confused.

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

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



  • 7.  RE: ESXi Switch details

    Posted Oct 09, 2017 01:34 AM

    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.



  • 8.  RE: ESXi Switch details

    Posted Oct 09, 2017 07:24 AM

    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


  • 9.  RE: ESXi Switch details

    Broadcom Employee
    Posted Oct 12, 2017 12:19 PM

    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"



  • 10.  RE: ESXi Switch details

    Posted Oct 12, 2017 10:16 PM

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

    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 ?



  • 11.  RE: ESXi Switch details

    Broadcom Employee
    Posted Oct 16, 2017 02:26 AM

    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