Hyper-V Getting MAC Address using VM Name

As part of my automated provisioning (yes – System Center and Sysprep will probably be a better option, but hey whatever) script, I need to be able to automatically assign an IP address to a VM. At this point, the only way I can see this being a possibility is to mount the VHD before booting then copying a script that will set the correct IP address to an autostart location.

The ‘script’ is broken down into two parts. The first needs to run on the node, and create the second script inside the VHD. The second script then needs to identify what network adapter/s are present and assign the correct IP address to each.

The first challenge is finding out how to have the second script identify the correct adapter. I initially though about testing connectivity after the IP address was set, and upon a failure, revert the changes and try the next adapter present. Rather than doing this, I found you can get the MAC address for a VM from the Hyper-V node, and filter based on which Virtual Switch the interface is attached to:

The following example will get the MAC address for a VM based on the VM name, and the network it is attached to:

This returns a MAC address.

I believe I can then use this MAC address in the second part of the script to pull the network adapter name.

Something along the lines of this:

Once I have the correct adapter name, I can use this in an IP address setting script to set the correct IP / gateway etc essentially automating the networking side of provisioning.

At this point there are a few things I have yet to confirm that might make the above attempt futile. First, I do not know if I can run a powershell script on startup – I know there are issues with signed code etc, and this might mean a freshly provisioned system will not allow unsigned code to run – especially if it needs administrator permissions. Second – I don’t know how this will work with a sysprepped image. It is possible (probable?) that with a sysprep image, the network configuration information could be copied to the sysprep config eliminating the need for an autorun script.

You can see an example of a powershell script to assign IP addresses here: https://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/040b8993-d737-4436-8fb1-29187583e7d1/


I have spent the last few weeks organizing a change for my domain registrar (websitespot.com) so I can have full control over the name servers for the domain. I have done this because I was previously unable to host websites due to the dynamic nature of my IP address.

No problems anymore. I have purchased custom dns services from dyndns.org and by using their name servers, I can update the IP address for the domain name when needed using their client.

Total cost for one year (not including my own internet, server costs) around $32. Thats the .com domain for about $6.95 and the custom DNS for about $25 (US$)

Next up (after saving enough) I’m planning on getting a couple UPS’s to make sure that turning on the microwave and jug at the same time doesn’t kill the power to the servers – and the rest of my house.

New Servers. Dell Poweredge.

I have recently purchased two Dell servers (via Yahoo Auctions Japan). I have a Poweredge 650 and a Poweredge 850. I have set the 650 up as a router (I know, complete overkill) running pfsense – a great free firewall system that supports a huge variety of hardware. I tried some other firewall systems, but none would detect the raid card, so I really had no choice.

To go into a bit more detail regarding the ‘overkill’ – The system (650) is running a 2.4ghz Pentium 4, with a gig a ram and four gigabytes of raid0 hard drive space. The system is usually running with about 4% cpu and 12% memory usage, but I’ve had it jump up to 60% sometimes. Now I wont have a problem with the router dying with all that P2P traffic over my fiber (100mbps) connection.

The other server (850) I have setup as a domain controller / mail server / web server (apahce) with the usuals PHP, MYSQL and so on. It is currently running this website. Only problem is I haven’t (as of yet) setup a backup routine. So if this dies, I’m going to be very sad. Its currently running a dual core 3ghz Pentium 4 with two gigs of ram and around 40gb of hard drive space.

The overall cost was very reasonable. The 650 set me back about 10,500 yen ($100) and the 850 was around 16,000 yen ($150) . Only problem was that I was orignally trying to build the servers myself. I had picked up a 650 and 850 server chassis for about 2000 yen ($20) and ordered the motherboard and other parts from the US.

The cost of the motherboard and backplane board cost more than buying the whole second hand 850. So now I have alot of unused second hand parts for the servers. If you are interested in purchasing them (in Japan) pop me an email.

© 2017 Chris's Blog

Theme by Anders NorénUp ↑