PowerCLI: how to change DNS on ESXi hosts?

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)
}
}

About admin

Check Also

PowerCLI: how to get unreserved CPU and Memory resource for each ESXi host?

I had reservation for some VMs in clusters, I wanted to find out how much …

Leave a Reply

Your email address will not be published. Required fields are marked *