Rashida11
Contributor
Contributor

List all the NICS with corresponding MAC addresses and IP addresses

Hi all , i need to do some vSwitch label changing soon . before i commence . I wanted a VI Script to get all the vm IN A CLUSTER and list all the NICS with corresponding MAC addresses and IP addresses. Noting that each VM has two to three NICS.

Cheers

0 Kudos
2 Replies
langleyj
Contributor
Contributor

This will give you the MAC address:

Get-VM | select name, @{Name="mac"; expression={foreach($nic in (Get-View $_.ID).guest.net) {$nic.macAddress}}}

and you should be able to get IPAddr with a foreach loop like:

$vm=""

IPAddr

foreach($ip in $_.IPAddress){

$vm.IPAddr = $ip

}

0 Kudos
esarakaitis
Enthusiast
Enthusiast

try this

$VMs = get-vmhost | Get-VM
foreach ($VM in $VMs){
    $VMx = Get-View $VM.ID
	$HW = $VMx.guest.net
	foreach ($dev in $HW)
    {
        foreach ($ip in $dev.ipaddress)
        {
            $dev | select @{Name = "Name"; Expression = {$vm.name}},@{Name = "IP"; Expression = {$ip}}, @{Name = "MAC"; Expression = {$dev.macaddress}}
        }
    }
}

http://www.vmwarescripting.com

0 Kudos