Change/Update DNS or domain with vSphere PowerCLI

There was some confusion on how to specify multiple dns server ip address or domain search names with the Set-VMHostNetwork cmdlet. Turns out is a simple comma separated list that get treated as a parameter array. Here is an example.

Connect-viserver vCenterServerFQDNorIP
$ESXiHosts  = Get-VMHost
foreach ($esx in $ESXiHosts) {
     Get-VMHostNetwork | Set-VmHostNetwork -DomainName  eng.example.com -DnsAddress dnsAddress1,dnsAddress2
}

Or in one-line

Get-VMHost | Get-VMHostNetwork | Set-VmHostNetwork -DomainName  eng.example.com -DnsAddress dnsAddress1,dnsAddress2

Leave a Reply