Hi,
Would like to know if there are any scripts to generate a time-sync report for the ESXi (4.0) hosts and VC in my Vcentre 4.0 infrastructure and send an email daily with the status ?
This is to ensure all the system time for the hosts are in sync. Am not good at scripting and some help would be appreciated ! Thanks
This is to check all the hosts using right NTP
Get-VMHost |Sort Name|Select Name, @{N=“NTPServer“;E={$_ |Get-VMHostNtpServer}}, @{N=“ServiceRunning“;E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq “ntpd“}).Running}}
if you do happen to have a host with an incorrect NTP server then you can set it like this:
Add-VMHostNtpServer -VMHost MYHost -NtpServer ‘ntp.mydomain.com‘
Or if one of the services has stopped you can start it again with the following:
Get-VmHostService -VMHost MyHost | Where-Object {$_.key -eq “ntpd“} | Start-VMHostService
Hi,
Thanks for your reply. However, this only checks if im connected to the right NTP Server and the service status. What I would require help is for me to be able to use a script to obtain the time stamp of all the ESXi hosts in a report format which i would in turn use to compare to my AD for accurate time sync. Thanks
This is crude, but this is what I'm using:
foreach($myHost in (Get-VMHost)) { $myView = Get-View $myHost.Extensiondata.ConfigManager.dateTimeSystem; Write-Host $(Get-Date) " " $myView.QueryDateTime() " " $myHost.Name; }
thread moved to VMware vSphere™ PowerCLI Community
Hi,
Thanks for your reply. I aint good at Powershell and as such would appreciate if you guide me into putting the sample Esxi host names into the script.
(Ex Server_Alpha, Server_Bravo, Server_Charlie)
Btw, do you have a sample output report of the script ?
Thanks so much.
Robert LeBLanc wrote:
This is crude, but this is what I'm using:
foreach($myHost in (Get-VMHost)) { $myView = Get-View $myHost.Extensiondata.ConfigManager.dateTimeSystem; Write-Host $(Get-Date) " " $myView.QueryDateTime() " " $myHost.Name; }
You can use something like this
$esxNames = "Server_Alpha", "Server_Bravo", "Server_Charlie"
foreach($myHost in (Get-VMHost -Name $esxNames)) { $myView = Get-View $myHost.Extensiondata.ConfigManager.dateTimeSystem Write-Host $(Get-Date) " " $myView.QueryDateTime().ToLocalTime() " " $myHost.Name }
Note that I convert the system time to local time (it is returned in UTC).
For each server, the script will produce a line like this
29-03-2012 07:40:54 29-03-2012 05:40:32 Server_Alpha
There is a similar thread called PowerCLI: Detect incorrect Time Configuration
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference