I had a situation to update the DNS servers on multiple esxi hosts. When you want to do bulk actions, PowerCLI is your friend!
1. Connect to the vCenter Server:
Connect-VIServer VC_ADDRESS
2. Create a variable which includes the IP address of the DNS Server
$dnsServers = '172.16.10.5'
3. Remove the old DNS servers from the esxi host and add the new addresses:
Get-VMHost | %{
$esxcli = Get-EsxCli -VMHost $_ -V2
$esxcli.network.ip.dns.server.list.Invoke() | select -ExpandProperty DNSServers | %{
$sOldDns = @{
server = $_
}
$esxcli.network.ip.dns.server.remove.Invoke($sOldDns)
}
$dnsServers | %{
$sDns = @{
server = $_
}
$esxcli.network.ip.dns.server.add.Invoke($sDns)
}
}