VMware Cloud Community
thb_
Enthusiast
Enthusiast
Jump to solution

get MacAdress

im trying to retrive the MacAdress of a VM as String. Lets say i have a virtual machine with only one vmxnet3 nic. As Input i select vc:virtualmachine.

How do i get the mac adress of that one nic?

There must be a simple way or ?

0 Kudos
1 Solution

Accepted Solutions
schepp
Leadership
Leadership
Jump to solution

Hi,

I use this little script to get the MAC of my newly created VMs.

newVMObject is my vc:virtualmachine Input

var deviceArray = newVMObject.config.hardware.device; 

if (!deviceArray) throw "Error getting hardware config array of VM"; 

for (var i in deviceArray) { 

    var currentDevice = deviceArray.pop(); 

    if (currentDevice) { 

        if (currentDevice instanceof VcVirtualE1000 || 

            currentDevice instanceof VcVirtualPCNet32 ||  

            currentDevice instanceof VcVirtualVmxnet ||  

            currentDevice instanceof VcVirtualVmxnet2 ||

            currentDevice instanceof VcVirtualVmxnet3 ||  

            currentDevice instanceof VcVirtualVmxnet) { 

                var mac = currentDevice.macAddress; 

        } 

    } 

Tim

View solution in original post

0 Kudos
1 Reply
schepp
Leadership
Leadership
Jump to solution

Hi,

I use this little script to get the MAC of my newly created VMs.

newVMObject is my vc:virtualmachine Input

var deviceArray = newVMObject.config.hardware.device; 

if (!deviceArray) throw "Error getting hardware config array of VM"; 

for (var i in deviceArray) { 

    var currentDevice = deviceArray.pop(); 

    if (currentDevice) { 

        if (currentDevice instanceof VcVirtualE1000 || 

            currentDevice instanceof VcVirtualPCNet32 ||  

            currentDevice instanceof VcVirtualVmxnet ||  

            currentDevice instanceof VcVirtualVmxnet2 ||

            currentDevice instanceof VcVirtualVmxnet3 ||  

            currentDevice instanceof VcVirtualVmxnet) { 

                var mac = currentDevice.macAddress; 

        } 

    } 

Tim

0 Kudos