Not long ago, we updated our internal DNS to use Cisco Umbrella (aka OpenDNS). During the migration, we needed to update all of the DNS settings on our ESXi hosts. There is a built-in cmdlet called Set-VMHostNetwork which will update the settings. The best practice is to always have multiple DNS servers, so doing that is fairly easy but you will need to create an array with multiple addresses.
To create an array, you have to declare a varaible and assign it to an empty array using @(). Afterwards, you can add your data into the empty array.
The code below assume you already have a connection to vCenter. If not use a Connect-ViServer cmdlet to connect first. The code will get all of the ESXi hosts connected to a vCenter and update their DNS settings with the new settings you specify:
$dnsaddress = @() $dnsaddress += "18.104.22.168" $dnsaddress += "22.214.171.124" Get-VMHost | Get-VMHostNetwork -ErrorAction SilentlyContinue | Set-VMHostNetwork -DnsAddress $dnsaddress