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

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

body

-----------------------------------------------------------------------------------------------------------------------------------------------------
import-module vmware.vimautomation.core

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


$esxhost | %{

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

$esxcli.network.ip.dns.server.list.Invoke() | select -ExpandProperty DNSServers | %{

$sOldDns = @{

server = $_

}

$esxcli.network.ip.dns.server.remove.Invoke($sOldDns)

}
}

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

$sDns = @{

server = $_

}

$esxcli.network.ip.dns.server.add.Invoke($sDns)


}

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

text

Share this

About the Author

Jitendra
Jitendra
Contributer VMwareDiary.com

User's Comments


 
Please SignUp/Login to comment...

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