tekhie
Contributor
Contributor

which nic is my vm using ?

Jump to solution

hi - is there a way to get a list of vm's  and to identify the pNIC that the vm traffic is going through.  I am using 'route based on originating port id' for the load balancing method and am interested to see how many vm's are using each of the active physical uplinks on the vswitch

thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Your foreach loops were not correct.

Try it perhaps like this

#Define some variables 
$vcServer
= "xxxxx"
$cluster = "DEV_Cluster"
$esxcred
= import-pscredential -Path D:\VMwebsite\Vmware\password\ESX.enc.xml $vccred = import-pscredential -Path D:\VMwebsite\Vmware\password\VCentre.enc.xml $filelocation = "C:\Myscripts\Scripts\VMUplinks.csv" $Report = @() #Connect to vCenter
Connect-VIServer $vcServer -Credential $vccred | Out-Null
#
Connect to ESX hosts in cluster
foreach ($esx in Get-Cluster $cluster | Get-VMHost) {     Connect-VIServer $esx -Credential $esxCred   
#Retrieve the esxcli instances and loop through them
    foreach($esxcli in (Get-EsxTop -CounterName netport)) {         $NetworkInfo = "" | select-Object HostName , VMName , Uplink
       
$NetworkInfo.HostName = $esx.Name         $NetworkInfo.VMName = $esxcli.ClientName         $NetworkInfo.Uplink = $esxcli.TeamUplink         $Report += $NetworkInfo
    } #Disconnect from ESX host
    Disconnect-VIServer $esx.name -Confirm:$false
} $Report | Export-CSV $filelocation
#
Disconnect from vCenter
Disconnect-VIServer $vcServer -Confirm:$false | Out-Null


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

View solution in original post

0 Kudos
6 Replies
Bytewurm
Contributor
Contributor

Hi,

if you are using vsphere4 try to use "esxtop" and press "n" to view network-device relations, I can currently not verify - only ESX 3.x around me at the customers' playgrounds and my lab is out of reach. To get a list with correlated NICs is some scripting work then, but maybe there is a PowerCLI-way, too?

Source: http://blogs.vmware.com/networking/2009/04/which-nic-is-my-vm-using-load-balancing-visibility-with-v...

Regards

Michael

0 Kudos
tekhie
Contributor
Contributor

HI michael thanks for the info -  i was aware of the esxtop method too in vsphere - not sur eits the same in VI3.  I have been looking for the information using powershell but have been unable to find out how to get it - does anybody in the community know ? Im not sure whether i should be looking at the VM, Host or Network values in order to find it

0 Kudos
Rubeck
Virtuoso
Virtuoso

LucD might have some info on this, which may inspire you... http://www.lucd.info/2010/12/03/hitchhikers-guide-to-get-esxtop-part-1/

/Rubeck

tekhie
Contributor
Contributor

hi rubeck - thats great - i used the information and have tried to put a script together to go through each VM in a cluster and report HostName, VMName and Uplink.  WHen running however i get the correct number of VM's and Uplink information, but my Hostnames are all the same (VMLON014) - should be a mic of VMLON013 and VMLON014. Something wrong with the nesting i think - could anyone advise me how to reformat - script attached

0 Kudos
LucD
Leadership
Leadership

Your foreach loops were not correct.

Try it perhaps like this

#Define some variables 
$vcServer
= "xxxxx"
$cluster = "DEV_Cluster"
$esxcred
= import-pscredential -Path D:\VMwebsite\Vmware\password\ESX.enc.xml $vccred = import-pscredential -Path D:\VMwebsite\Vmware\password\VCentre.enc.xml $filelocation = "C:\Myscripts\Scripts\VMUplinks.csv" $Report = @() #Connect to vCenter
Connect-VIServer $vcServer -Credential $vccred | Out-Null
#
Connect to ESX hosts in cluster
foreach ($esx in Get-Cluster $cluster | Get-VMHost) {     Connect-VIServer $esx -Credential $esxCred   
#Retrieve the esxcli instances and loop through them
    foreach($esxcli in (Get-EsxTop -CounterName netport)) {         $NetworkInfo = "" | select-Object HostName , VMName , Uplink
       
$NetworkInfo.HostName = $esx.Name         $NetworkInfo.VMName = $esxcli.ClientName         $NetworkInfo.Uplink = $esxcli.TeamUplink         $Report += $NetworkInfo
    } #Disconnect from ESX host
    Disconnect-VIServer $esx.name -Confirm:$false
} $Report | Export-CSV $filelocation
#
Disconnect from vCenter
Disconnect-VIServer $vcServer -Confirm:$false | Out-Null


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

View solution in original post

0 Kudos
tekhie
Contributor
Contributor

excellent - thanks everybody for the assistance

0 Kudos