Customisation: Lesson 1 – Time Source

I thought I would help people learn the VI Toolkit whilst also creating a nice script which you can customise to your own environment, hopefully this is a script that will save you time in the future.

The script we are going to build together in step by step instructions is a Customisation script.

You have built your host and now have to go through the configuration and tweaks of all the after-build areas, you have to make sure that these are setup the same on each host so that things like VMotion and DRS work so what better than a script to help us limit the amount of mistakes when typing names or missing steps.

Imagine you have built your host, what customisations do you apply to it ? Please let me know and I will make sure I cover it in these lessons so that people can include it in there build script and save everyone time.  Please leave a comment with your suggestions.

Lesson 1 – setting the NTP server.

We all know time is important, without time things stop working, more than a couple of minutes out can cause major issues so the first thing we do just after building our host is to setup the NTP server.

 

You could log into Virtual Center, click on the new host and select the configuration, Time Configuration selection remove the default setting for ‘127.127.1.0’ and add your own time source but we don’t want to do that because we want to script it.

With the VI Toolkit we are given Remove-VMHostNtpServer and Add-VMHostNtpServer so lets make use of these cmdlets to remove the default NTP server and add our own one in.

 

First lets store our server name in a variable:

$VMHost = myhost1.mycompany.com

Now we have this stored lets remove the default NTP Server from that host:

Remove-VMHostNtpServer -VMHost $VMHost -NtpServer 127.127.1.0

After this we can add our new NTP Server:

Add-VMHostNtpServer -VMHost $VMHost -NtpServer ntp.mycompany.com

 

image

 

So we now have a ntp server added, wow that didn’t save much time, but wait till we build this script up to add in our networks, configure precise settings etc, then we will have an extra 30 mins lunch break whilst our script does the work !

 

Our Script So Far:

 

Connect-VIServer myviserver

$VMHost = myhost1.mycompany.com

Remove-VMHostNtpServer -VMHost $VMHost -NtpServer 127.127.1.0

Add-VMHostNtpServer -VMHost $VMHost -NtpServer ntp.mycompany.com

-Alan

Alan

Alan Renouf has a role of Automation Frameworks Product Manager at VMware responsible for providing the architects and operators of the cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/vipowershell and has a personal blog at http://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

You may also like...

9 Responses

  1. Mario Vinet says:

    If I may also add, configure Vswitch would be nice. Service Console Memory, Enable in Security Profiles a check box (like NIS client).

    Cody and Virtu-Al I have to agrre with Virtu-Al I’m completely ignorant in Vi-Toolkit/Powershell so the more it’s basic the better!

    • Virtu-Al says:

      Thanks Mario, I will definitely include these, hadn’t thought about service console memory, good one !

  2. Virtu-Al says:

    Cody,

    Thanks for the suggestion, its a great Idea but I want to introduce people to these things slow, this is a wonderful more advanced way to configure the hosts but perhaps we will leave this until we have covered the basics :) Thanks for our input.

  3. LucD says:

    Great idea Alan.
    There are some good posts with suggestions for configuring an ESX in the VITK community.
    Have, for example, a look at http://communities-origin.vmware.com/message/1040385#1040385 and http://communities-origin.vmware.com/docs/DOC-8170.

  4. Cody Bunch says:

    so rather than $VMHost = “myhost.mycompany.com”, we could do a few things, optimally would be take input from the pipeline into that variable:

    begin {
    $ntpserver = ‘pool.ntp.org’
    }

    process {
    if ( $_ -isnot [VMware.VimAutomation.Client20.VMHostImpl] ) { continue }
    Remove-VMHostNtpServer -VMHost $_ -NtpServer ‘127.127.1.0‘
    Add-VMHostNtpServer -VMHost $_ -NtpServer $ntpserver
    }

    We can then add more things into the process block as we grow the script. This would allow us to better target the hosts that we need to make the changes on.

  5. Virtu-Al says:

    @Duncan
    That’s a good one

  6. Duncan says:

    active/passive setup for VMkernel and Service Console

  7. Virtu-Al says:

    Thanks Duncan, I will make sure I cover this after the basics

  8. Duncan says:

    Disk.UseDeviceReset = 0

    So people know how to set an advanced setting…

Leave a Reply

%d bloggers like this: