VMware Powercli Script Configure DNS server, DNS domain, and NTP services

Here’s very useful Powercli Script for VMware Administrator to set DNS server, DNS domain and NTP server values, and restart NTP.

Illustrated Examples: ESXI Configuration: Time Configuration and DNS and Routing

ESXI NTP and DNS/Routing Configure Settings:

ntpsettings

dnsanddomain

Leveraging PowerCLI Script  that configure DNS server, the DNS domain, and NTP, and starts NTP service after completing configuration.

I. Prerequisites:
a.Identify DNS server, DNS domain, and NTP information:

NTP and DNS will be same address due to NTP is enabled and reference  to pool.ntp.org

Figure #1- DNS server configuration example:-Open DNS Manager on Domain Controller or Windows Admin Tools:

dnsserverconfigurationFigure #2 – Enabling Windows 2012 to point NTP pool.ntp.org  by running command -PS C:\Windows\system32> w32tm /config /manualpeerlist:pool.ntp.org /syncfromflags:MANUAL
The command completed successfully.
PS C:\Windows\system32> Stop-Service W32Time
PS C:\Windows\system32> Start-Service W32Time

enablingntpserviceonwindows2012

Figure#3-Validate NTP status by running command
-PS C:\Windows\system32> w32tm /query /status

NTPstatusonwindows2012

 

Solution make things easier , using Powercli DNS and NTP script –
script code:

##############################################################################

# PowerCLI Script to Configure DNS and NTP on ESXi Hosts
# PowerCLI Session must be connected to vCenter Server using Connect-VIServer
# Prompt for Primary and Alternate DNS Servers
$dnspri = read-host “Enter Primary DNS”
$dnsalt = read-host “Enter Alternate DNS”
# Prompt for Domain
$domainname = read-host “Enter Domain Name”
#Prompt for NTP Servers
$ntpone = read-host “Enter NTP Server One”
$ntptwo = read-host “Enter NTP Server Two”
$esxHosts = get-VMHost
foreach ($esx in $esxHosts) {
   Write-Host “Configuring DNS and Domain Name on $esx” -ForegroundColor Green
Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -DomainName $domainname -DNSAddress $dnspri , $dnsalt -Confirm:$false
Write-Host “Configuring NTP Servers on $esx” -ForegroundColor Green
Add-VMHostNTPServer -NtpServer $ntpone , $ntptwo -VMHost $esx -Confirm:$false
Write-Host “Configuring NTP Client Policy on $esx” -ForegroundColor Green
Get-VMHostService -VMHost $esx | where{$_.Key -eq “ntpd”} | Set-VMHostService -policy “on” -Confirm:$false
   Write-Host “Restarting NTP Client on $esx” -ForegroundColor Green
Get-VMHostService -VMHost $esx | where{$_.Key -eq “ntpd”} | Restart-VMHostService -Confirm:$false
}
Write-Host “Done!” -ForegroundColor Green
Write-Host “Done!” -ForegroundColor Green
###########################################################################

II. Download NTP_DNS PowerCLI Scource Code:

[embeddoc url=”http://blog.itsysintegration.net/wp-content/uploads/2015/11/NTP_DNS.zip” download=”all”]

III. Step by Step How To Configure DNS and NTP for newly built ESXI host.

a. Launch PowerCli and Run As Administrator

openpowercli

b. Log into the ESXI Host via PowerCLI

esxilogon

c. Execute NTP_DNS.ps1> type .\NTP_DNS.ps1

Ntp

d. You will get a prompt to input Primary, Alternative DNS, Domain Name, NTP Server one and two.:

primarydns

e. DNS_NTP script updates the both DNS and NTP on ESXI Host and Start NTP services.

finaldnsntpssettings

NTPrestrt

 

Reference:

NTP and DNS PowerCLI cmd-let
https://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Set-VMHostNetwork.html


Enabling NTP on Windows 2013
http://www.sysadminlab.net/windows/configuring-ntp-on-windows-server-2012


Leave a Reply

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