Tuesday, May 15, 2012

PowerCLI - ESXi network interfaces

I have added new gigabit NIC`s on all the ESXi servers and before making any modifications to the traffic flows I wanted to see that the network was up and running. So, the following script came in handy:


### Get pnics and their link speed

get-vmhost | foreach {
$_.Name
$pnics = $_.NetworkInfo.ExtensionData2.NetworkInfo.Pnic
foreach ($p in $pnics) {
$row=""
$row += $p.Device + " " + $p.LinkSpeed.SpeedMB
$row
}
}


After finishing all reconfigurations on ESXi networking - mainly redistributing traffic flows on the newly installed NIC`s, I felt the need to have a quick look over the deeds just done. The idea was to check  that ESXi hosts had the correct vmk interfaces and the correct IP addresses. So, another small bit of scripting:


###Get vmk interfaces and IP addresses for all hosts
foreach ($vmh in get-vmhost)
{
$row = ""
$row += $vmh.Name + " "
foreach ($i in $vmh.NetworkInfo.ExtensionData2.NetworkConfig.Vnic)
{
$vmk= $i.Device
$row += $vmk + " "
$vmkip = $i.Spec.Ip.IpAddress
$row += $vmkip + " "
$vmksubnet = $i.Spec.Ip.SubnetMask
$row += $vmksubnet + " "
}
$row
}

No comments: