Hi,
Is there any way to get and set the ESX system time using PowerShell ?
Thanks,
Hogger
get-date After you have connected to the host
Ok so that doesn't work. You can set the NTP server with set-vmhostntpserver
Message was edited by: Chamon
The Get-Date cmdlet will give you the time on the machine where you execute the cmdlet.
To get the time from an ESX server you can do the following
$esxName = <ESX-name> Connect-VIServer -Server $esxName -Credential (Get-Credential) (Get-View ServiceInstance).CurrentTime() Disconnect-VIServer -Confirm:$false
Note that you have to connect to the ESX server for this method.
If you execute the method against the vCenter you will get the time from the vCenter server.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can you set the time? Wu use an NTP server so we don't set the time on the host after the instal just the NTP servers. Trying to learn PS. Next lesson is about Objects so hopefully that will help with this sort of thing. Any advise on training material?
Yes, you could use the UpdateDateTime method.
You could have a look at some of my blog posts. See my signature.
I have a few on the SDK and I have the My PS library post which contains some links to good material.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great Thanks
Hi,
You can get\set date and time of ESX using below code snippet
$creds = Get-VICredentialStoreItem -file C:\vicredentials.xml Connect-VIServer -Server $creds.Host -user $creds.User -password $creds.Password #For current time (Get-View ServiceInstance).CurrentTime() $vmhost = Get-vmhost $creds.Host |Get-View $dtsystemMoRef = $vmhost.ConfigManager.DateTimeSystem $dtsystem = Get-View $dtsystemMoRef #For changing datetime, change the $dateconfig $dateConfig = "Thursday, February 04, 2010 6:55:18 AM" $dtsystem.UpdateDateTime($dateConfig)
Hope this helps
Thanks for your excellent reply !!!!
Worked like a champ.
Thanks! Works like a charme!