Automation

 View Only
  • 1.  userful info fromesxcfg-* by powercli

    Posted Jul 12, 2015 05:51 AM

    I often asked by network team, mac info/vlan info. I ended up running below 3 cmd to explain them the stuff. can we get this in powercli & xls ?

    Vmhost/Nic/Nic Mac/nic is part of which vswitch/ vmkernel ports & they IP...

    ~ # esxcfg-vmknic -l

    ~ # esxcfg-nics -l

    ~ #

    ~ # esxcfg-vswitch -l

    Thanks



  • 2.  RE: userful info fromesxcfg-* by powercli
    Best Answer

    Posted Jul 12, 2015 12:40 PM

    You can do all that with the Get-EsxCLi cmdlet.

    Like this

    $esxcli = Get-EsxCli -VMHost MyEsxi

    # esxcfg-vmknic -l

    foreach($vmk in $esxcli.network.ip.interface.list()){

        $esxcli.network.ip.interface.ipv4.get($vmk.Name) |

        Select Name,@{N='PortGroup';E={$vmk.Portgroup}},@{N='IP Familiy';E={'IPv4'}},

            @{N='IP Address';E={$_.IPv4Address}},

            @{N='Netmask';E={$_.IPv4Netmask}},

            @{N='Broadcast';E={$_.IPv4Broadcast}},

            @{N='MAC';E={$vmk.MACAddress}},

            @{N='MTU';E={$vmk.MTU}},

            @{N='TSOMSS';E={$vmk.TSOMSS}},

            @{N='Enabled';E={$vmk.Enabled}},

            @{N='Type';E={$_.AddressType}}

    }

    # esxcfg-nic -l

    $esxcli.network.nic.list() |

    where{$_.Name -match 'vmnic'} |

    Select Name,@{N='PCI';E={$_.PCIDevice}},

        Driver,Link,Speed,Duplex,MACAddress,MTU,Description

    # esxcfg-vswitch -l

    foreach($vss in $esxcli.network.vswitch.standard.list()){

        $vss | Select @{N='Switch Name';E={$_.Name}},

        NumPorts,UsedPorts,ConfiguredPorts,MTU,@{N='Uplinks';E={$_.Uplinks -join ','}}

      

        $esxcli.network.vswitch.standard.portgroup.list() |

        where{$_.VirtualSwitch -eq $vss.Name} |

        Select @{N='Portgroup Name';E={$_.Name}},

            VLANID,@{N='Used Ports';E={$_.ActiveClients}},

            @{N='Uplinks';E={

                ($esxcli.network.vswitch.standard.portgroup.policy.failover.get($_.Name) |

                Select -ExpandProperty ActiveAdapters) -join ','

            }}

    }

    foreach($vds in $esxcli.network.vswitch.dvs.vmware.list()){

        $vds | Select @{N='DVS Name';E={$_.Name}},

        NumPorts,UsedPorts,ConfiguredPorts,MTU,@{N='Uplinks';E={$_.Uplinks -join ','}}

      

        $vds.DVPort |

        Select DVPortgroupID,InUse,@{N='Client';E={$_.CLient -join ','}}

    }



  • 3.  RE: userful info fromesxcfg-* by powercli

    Posted Jul 13, 2015 08:36 AM

    i exported in csv but for some reasons the o/p shows  & as u can see the IP is missing too

             

    NamePortGroupIP FamiliyNetmaskBroadcastMACMTUTSOMSSEnabledType
    vmk0Management NetworkIPv4255.255.255.0150065535TRUESTATIC
    vmk1Management NetworkIPv4255.255.255.0150065535TRUESTATIC
    vmk2Management NetworkIPv4255.255.255.0150065535TRUESTATIC
    vmk0NFSIPv4255.255.255.0150065535TRUESTATIC
    vmk1NFSIPv4255.255.255.0150065535TRUESTATIC
    vmk2NFSIPv4255.255.255.0150065535TRUESTATIC
    vmk0VmotionIPv4255.255.255.0150065535TRUESTATIC
    vmk1VmotionIPv4255.255.255.0150065535TRUESTATIC
    vmk2VmotionIPv4255.255.255.0150065535TRUE

    STATIC

        

    ~ # esxcfg-vmknic -l

    Interface  Port Group/DVPort   IP Family IP Address                              Netmask         Broadcast       MAC Address       MTU     TSO MSS   Enabled Type

    vmk0       Management Network  IPv4    xx                           255.255.255.0   xx    2c:xx:e0 1500    65535     true    STATIC

    vmk1       NFS                 IPv4      xxx                            255.255.255.0   xx    00:xx5c 1500    65535     true    STATIC

    vmk2       Vmotion             IPv4      xx                           255.255.255.0   xx5    00:xx:eb 1500    65535     true    STATIC

    ~ #



  • 4.  RE: userful info fromesxcfg-* by powercli

    Posted Jul 13, 2015 08:49 AM

    I updated the code, please try again.



  • 5.  RE: userful info fromesxcfg-* by powercli

    Posted Jul 16, 2015 12:10 AM

    Awesome

    To make it loop the entire VC & make it more meaningful that way  ... can we add the esxi node name in each of these ?

    eg current xls export has :- (missing the vmhost name )

    NamePortGroupIP FamiliyIP AddressNetmaskBroadcastMACMTUTSOMSSEnabledType

    thanks !