I'm looking for an easy way to get the date and time of an esx server in c#. This has to be the hardware time, so I think this is the BIOS time. When a VM reboots it normally gets the time of the BIOS time. It is that time I want as a datetime object.
I think I should use something like this:
private DateTime getTimeESX(Machine machine)
{
DateTime time = new DateTime();
Runspace runSpace = RunspaceFactory.CreateRunspace();
runSpace.Open();
Pipeline pipeline = runSpace.CreatePipeline();
Command getEsxCli = new Command("Get-EsxCli");
getEsxCli.Parameters.Add("Server", machine.IP);
Command getSysTime = new Command("system time get");
pipeline.Commands.Add(getEsxCli);
pipeline.Commands.Add(getSysTime);
Collection<PSObject> output = pipeline.Invoke();
foreach (PSObject psObject in output)
{
time = (DateTime)psObject.BaseObject;
}
return time;
}
Does someone has an idea how I could easily test this? I don't have an ESX running in my network.