Mark III Systems Blog

Auto Create Windows Server based DHCP and DNS records for VMs

Here is a little script I worked on to help automate the build out of a lab environment. I built this primarily to support a nested ESX and vCenter auto-deploy environment. The use case was fairly unique but I thought the code was cool and it may be helpful reference.

This script will...

  1. Take a VM name or partial with wildcard (or solo wildcards for that matter)
  2. Look into Windows based DHCP Server for existing reservations based on first NICs MAC
  3. Create reservation based on machine name and MAC if not found
  4. Place entry into AD integrated DNS for the new reservation
  5. Verify the DNS entry

The script assumes the runtime credentials of the user executing the script.

The script assumes that DHCP and DNS are running on the same server.

An example of the script execution is shown below.

.\create-dhcp-dns-for-vms.ps1 -esx_vm_name "n01-esx*" -vcenter_build vcsa01.lab.loc -scope_id "172.25.201.0" -dhcp_server "dc04.lab.loc" -zone_name "bryan.loc"

The script has also been built to check the actions using a -dry_run parameter to provide the boolean for the -WhatIf on action cmdlets. This is a cool little technique I like to use.

Enjoy!

Git Hub Gist