VMware {code} Community
fredoenglish
Contributor
Contributor
Jump to solution

How to get Virtual Machine MAC Address on which vmware tools is not installed

Hello,

I'm trying to put the MAC Address of a virtual machine in a string. At the beginning, I was using this script :

     strMACAddress = objVM.guest.net[0].macAddress;

But as specified in the title, the vmware tools aren't installed on the VM. I've found a similar post in vSphere Web Services SDK :

http://communities.vmware.com/thread/254204

In this post, it's specified to use the VcVirtualEthernetCard() scripting object. I'm new on Orchestrator and I don't understand how to link "myVcVirtualEthernetCard" to my Virtual Machine Object "objVM".

Example :

IN : objVM (VcVirtualMachine)

OUT : macAddress

     var myVcVirtualEthernetCard = new VcVirtualEthernetCard();

     var macAddress = myVcVirtualEthernetCard.macAddress;

Thank you for your help.

Regards,

Fred

Reply
0 Kudos
1 Solution

Accepted Solutions
tschoergez
Leadership
Leadership
Jump to solution

Hi!

You can loop through the config.hardware.device-Array of the VM:

IN: vm (Vc:VirtualMachine)

OUT: macAddresses (Array/String)

//initialize macAddresses array (to make a push() possible later)
macAddresses = new Array();
var deviceArray = vm.config.hardware.device;
if (!deviceArray) throw "Error getting hardware config array of VM";
    System.debug("deviceArray: " + deviceArray);
//loop through array, find NICs and retrieve there MACs
for (var i in deviceArray) {
    var currentDevice = deviceArray.pop();
    if (currentDevice) {
        System.debug("currentDevice: " + currentDevice);
        if (currentDevice instanceof VcVirtualE1000 ||
            currentDevice instanceof VcVirtualPCNet32 ||
            currentDevice instanceof VcVirtualVmxnet ||
            currentDevice instanceof VcVirtualVmxnet2 ||
            currentDevice instanceof VcVirtualVmxnet) {
                System.debug("found network card on " + currentDevice);
                macAddresses.push(currentDevice.macAddress) ;
        }
    }
}

Please let me know if it works for your, or if you need some more information 🙂

Regards,

Joerg

View solution in original post

Reply
0 Kudos
3 Replies
tschoergez
Leadership
Leadership
Jump to solution

Hi!

You can loop through the config.hardware.device-Array of the VM:

IN: vm (Vc:VirtualMachine)

OUT: macAddresses (Array/String)

//initialize macAddresses array (to make a push() possible later)
macAddresses = new Array();
var deviceArray = vm.config.hardware.device;
if (!deviceArray) throw "Error getting hardware config array of VM";
    System.debug("deviceArray: " + deviceArray);
//loop through array, find NICs and retrieve there MACs
for (var i in deviceArray) {
    var currentDevice = deviceArray.pop();
    if (currentDevice) {
        System.debug("currentDevice: " + currentDevice);
        if (currentDevice instanceof VcVirtualE1000 ||
            currentDevice instanceof VcVirtualPCNet32 ||
            currentDevice instanceof VcVirtualVmxnet ||
            currentDevice instanceof VcVirtualVmxnet2 ||
            currentDevice instanceof VcVirtualVmxnet) {
                System.debug("found network card on " + currentDevice);
                macAddresses.push(currentDevice.macAddress) ;
        }
    }
}

Please let me know if it works for your, or if you need some more information 🙂

Regards,

Joerg

Reply
0 Kudos
fredoenglish
Contributor
Contributor
Jump to solution

Thank you very much Joerg !! It's exactly what I wanted.

Regards,

Fred

Reply
0 Kudos
NMWLabMan
Contributor
Contributor
Jump to solution



This really helped me out recently, thanks! One thing I had to change for my case was the second instance of this:


currentDevice instanceof VcVirtualVmxnet




To this:


currentDevice instanceof VcVirtualVmxnet3




As I was dealing with a VM that has a vmxnet3 adapter type and I noticed VcVirtualVmxnet was listed twice in the device instances, but no reference of vmxnet3.


Regards,


Darren

Reply
0 Kudos