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...
- Take a VM name or partial with wildcard (or solo wildcards for that matter)
- Look into Windows based DHCP Server for existing reservations based on first NICs MAC
- Create reservation based on machine name and MAC if not found
- Place entry into AD integrated DNS for the new reservation
- 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.