Scenario: You administer multiple physical locations, all with their own DNS and DHCP servers, hosted on VMware. Due to architectural changes to the environment, you need a quick & efficient way to make changes to the DNS Server options in DHCP.
Solution: PowerShell, PowerCLI, and netsh to the rescue! 🙂
[powershell]
$location = Read-Host "Please enter the folder or datacenter object you’d like to work with"
$secondary_dns = "10.10.10.1"
$VMs = Get-VM -Location $location | Where-Object {$_.Name -like "*dhcpserver*"}
foreach ($VM in $VMs){
$name = $VM.Guest.HostName
$octet = ([string]$VM.Guest.IPAddress).Split(".")
$primary_dns = $octet[0] + "." + $octet[1] + "." + $octet[2] + ".11"
netsh dhcp server "\\$name" set optionvalue 6 IPADDRESS "`"$primary_dns`"" "`"$secondary_dns`""
}
[/powershell]
You’ll definitely need to plug in the correct values for your environment, and you’ll need to Run As administrator in order to get it to work. Good luck! 🙂