VMware Cloud Community
steven_tolson
Enthusiast
Enthusiast

Query ESX host time...

Hello,

Does anybody know if it is possible to use the VI Toolkit to query the time of an ESX host?

Many thanks,

Steve

0 Kudos
3 Replies
LucD
Leadership
Leadership

Afaik there is currently no cmdlet in the VI Toolkit that returns the date/time for an ESX server.

So the SDK is the obvious next choice and there are indeed 2 methods to get the time of an ESX server.

Method 1:

On the ServerInstance MO there is a method called CurrentTime.

Method 2:

Since SDK 2.5 there exists a method called QueryDateTime on the HostDateTimeSystem MO.

But apparently both methods fail when called from PowerShell with the message:


Exception calling "CurrentTime" with "0" argument(s): "Value cannot be null.

Parameter name: destType"

Any explanation for this behavior would be welcome Smiley Wink

Luckily the ServerInstance MO has a property, called ServerClock, that does return the date and time in UTC.

This script shows you the date/time of an ESX server.


Get-VIServer -Server <your-ESX-server>



# Force load of the assembly

[http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("vmware.vim")



$svcRef = new-object VMware.Vim.ManagedObjectReference 

$svcRef.Type = "ServiceInstance" 

$svcRef.Value = "ServiceInstance" 

$serviceInstance = get-view $svcRef



$datetime = $serviceInstance.ServerClock



Write-Host $datetime

The script is attached since the forum SW has a mind of it's own.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

steven_tolson
Enthusiast
Enthusiast

Many thanks for your help LucD.

0 Kudos
LucD
Leadership
Leadership

Take not of the warning the comes with the ServerClock property !


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos