How to set the time of ESXi host using powercli

Why do we need to set the time in ESXi host?Let take a brief.

VM which running on the ESXi host which basically use the host time for the synchronization.During the time of VM reboot,the vmware tools will get the time from the host and set the as a system timing.

” These events synchronize time in the guest operating system with time in the host operating system even if VMware Tools periodic time sync is disabled, so it is important to make sure that the host operating system’s time is correct.”

VMware KB 1189 helps you to disable the time synchronization.

Suppose customer running an ERP application where the APP VM running in one host and DB on another host.During the time of the VM reboot,the VM will get the time from the host which is running.The Scenario where the DRS place the VM moves to different host not the actual DB VM host.Since the difference in time of all host.It will reflect the same in the VM level and makes confusion for customer.It is best pratice to run NTP local server and sync with NTP pool project.

Here I will demostrate using powercli
1.Connect to vCenter or host using powercli
Connect-VIServer -Server 192.168.1.2 -user root -password 123456

2.Next to run the ESXCli in Powershell,I’m getting the commands in the variable $esxcli

$esxcli = Get-EsxCli -VMHost 192.168.1.2

3.To list the available commands using the variable.

$esxcli.system

=====================
EsxCliElement: system

Elements:
———
boot
coredump
hostname
maintenanceMode
module
process
secpolicy
settings
shutdown
snmp
stats
syslog
time
uuid
version
visorfs
welcomemsg

4.To get the current host timing,you should use below command to get
> $esxcli.system.time.get()

5.To set the time in the host using the following command,first I will list the commands we can execute

$esxcli.system.time.set

TypeNameOfValue : VMware.VimAutomation.ViCore.Util10Ps.EsxCliExtensionMethod
OverloadDefinitions : {boolean set(long day, long hour, long min, long month,long sec, long year)}MemberType : CodeMethod
Value : boolean set(long day, long hour, long min, long month,long sec, long year)
Name : set
IsInstance : True

To Set : $esxcli.system.time.set(10,10,10,10,10,2010)
true
To view :esxcli.system.time.get()
2010-10-10T10:10:14Z

6.If you like to set the time in hardware clock,you can use esxcli command to set it
$esxcli.hardware.clock.set(10,10,10,10,10,2010)

So we have done.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s