Automation

 View Only
  • 1.  Script to change DNS and NTP needed

    Posted Feb 28, 2011 05:40 PM

    I am new to scripting. I am looking for a script that will change the two DNS server IPs as well as change the NTP server and restart the NTP servicen of an ESX host. Could it also make the change on an esx host as well as a datacenter level?

    Thanks!



  • 2.  RE: Script to change DNS and NTP needed

    Posted Feb 28, 2011 05:52 PM

    To change the DNS servers you can use the Set-VMHostNetwork cmdlet.

    Get-VMHost -Name MyEsx | Get-VMHostNetwork | Set-VMHostNetwork -DnsAddress "192.168.1.1","192.168.1.2"

    To change the NTP server use the Add-VMHostNtpServer cmdlet.



  • 3.  RE: Script to change DNS and NTP needed

    Posted Feb 28, 2011 06:56 PM

    what would the script be to pit it all together in one file?



  • 4.  RE: Script to change DNS and NTP needed

    Posted Feb 28, 2011 07:26 PM

    You mean something like this

    $esxName = "MyESX" 
    $dnsSrv
    = "192.168.1.1","192.168.1.2"
    $ntpSrv
    = "192.168.1.3"
    $esx = Get-VMHost -Name $esxName
    Get-VMHostNetwork
    -VMHost $esx | Set-VMHostNetwork -DnsAddress "192.168.1.1","192.168.1.2"
    Remove-VMHostNtpServer -VMHost $esx -NtpServer (Get-VMHostNtpServer -VMHost $esx) -Confirm:$false
    Add-VmHostNtpServer
    -VMHost $esx -NtpServer $ntpSrv

    Note that this will remove the current NTP server and replace it by the one(s) defined in $ntpSrv



  • 5.  RE: Script to change DNS and NTP needed

    Posted Mar 23, 2017 11:46 PM

    I am also very new to scripting and looking for something very similar. I need to query my hosts for incorrect dns and ntp settings and change them to the correct settings.  Thank you for your time.



  • 6.  RE: Script to change DNS and NTP needed

    Posted Mar 24, 2017 06:06 AM

    Why the testing, unless you need reporting on that?
    Why not just set the values?

    Like this

    $dnsSrv = "192.168.1.1","192.168.1.2"

    $ntpSrv = "192.168.1.3"

    foreach($esx in Get-VMHost){

        Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -DnsAddress $dnsSrv

       

        Remove-VMHostNtpServer -VMHost $esx -NtpServer (Get-VMHostNtpServer -VMHost $esx) -Confirm:$false

        Add-VmHostNtpServer -VMHost $esx -NtpServer $ntpSrv

    }