Please enable Javascript for better experience...
Setting up DNS and NTP servers on bulk of ESXi hosts
By Jitendra | Nov 10, 2021 | In Articles | Update: Nov 10, 2021 | Total Views [ 1328 ]
Taged In
(1 Like)

intial description

Setting up DNS and NTP servers on bulk of ESXi hosts

A simple script which will set up your DNS servers and the NTP servers which are really imprtant things to run your infra smooth and streamlined.

It also restarts the NTP and enable them if it was disabled.

Very easy to run no special requirement except powercli module and powershell to be installed where your are running this script.

It runs on cluster by cluster but you can run it on datacenter wise or on whole list of ESXi hosts in Vcenter. This script set up 3 DNS and 3 NTP servers in sequence you can customize this for 1 dns 1 NTP or so on.

Find the script below


import-module vmware.vimautomation.core

#This script removes your existing DNS and then start setting the new DNS which you put here
$ntpone = ""
$ntptwo = ""
$ntpthree = ""
connect-viserver -User -Password abc@123456
$esxhost = get-cluster -name Home-IT | get-vmhost
$esxcli = Get-EsxCli -VMHost $esxhost -V2

$esxhost | %{

$esxcli = Get-EsxCli -VMHost $_ -V2
$dnsServers = '','',''

$ | select -ExpandProperty DNSServers | %{

$sOldDns = @{

server = $_




Start-Sleep -Seconds 10
Write-Host "waiting for 10 seconds to apply new DNS settings"
$esxhost | %{
$esxcli = Get-EsxCli -VMHost $_ -V2
$dnsServers = '','',''
$dnsServers | %{

$sDns = @{

server = $_




Write-Host "Configuring NTP Servers on $esxhost" -ForegroundColor Green
Add-VMHostNTPServer -NtpServer $ntpone , $ntptwo , $ntpthree -VMHost $esxhost -Confirm:$false

Write-Host "Configuring NTP Client Policy on $esxhost" -ForegroundColor Green
Get-VMHostService -VMHost $esxhost | where{$_.Key -eq "ntpd"} | Set-VMHostService -policy "on" -Confirm:$false

Write-Host "Restarting NTP Client on $esxhost" -ForegroundColor Green
Get-VMHostService -VMHost $esxhost | where{$_.Key -eq "ntpd"} | Restart-VMHostService -Confirm:$false


You can comment and like this. I will surely reply your queries if any. Hope it helps you.

Looking for more help? create your IDs using signup and we will be ready to help.


Share this

About the Author


User's Comments

Please SignUp/Login to comment...

Or comment as anonymous...
* Name
* Email ID