Simple Host Time Information

Today I was asked if it was possible to pull certain time information from a VMware Host to ensure all hosts were not only using the same NTP server but also the same timezone and that they have the same time.  Obviously this is something that is very important for a number of reasons including security and auditing.

I sent the following one-liner (broken up here into several for ease of reading) and it was just what was needed.

Get-VMHost | Sort Name | Select Name, `
	@{N="NTPServer";E={$_ |Get-VMHostNtpServer}}, `
	Timezone, `
	@{N="CurrentTime";E={(Get-View $_.ExtensionData.ConfigManager.DateTimeSystem) | Foreach {$_.QueryDateTime().ToLocalTime()}}}, `
	@{N="ServiceRunning";E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq "ntpd"}).Running}} `
	| Format-Table -AutoSize

Sample output:

image

2 thoughts on “Simple Host Time Information

  1. Sanshis

    Hi Alan
    I really inspired by your scripts specially that are used in vCheck.
    personally i think you should promote get-view thn conventional powercli cmd-let.

    i couldn’t find much about “StorageResourceManager” if you write a bolg on this, will be grateful. I was trying to use “ApplyStorageDrsRecommendation_Task” for ‘clonevm_task’, but my concern was how i will aline “RecommendDatastores” for an object.

    for few host config check i had written a script earlier; i know for your knowledge this is of no use but this may help others

    $report= @()
    $ExportFilePath = “”
    $allhosts = get-view -Viewtype HostSystem -Property Config.service.Service, Name, config.AdminDisabled, Config.DateTimeInfo
    foreach($vmhost in $allhosts)
    {
    $HostConfig = “” | Select Name, LockDown, SSHPolicy, SSHRunningStatus, NTPRunningStatus, NTPpolicy, TimeZone, NTPServer1, NTPServer2
    $HostConfig.Name = $vmhost.Name
    $HostConfig.LockDown = $vmhost.config.AdminDisabled
    $sshservice = $vmhost.Config.service.Service | where -property “key” -match “ssh”
    $HostConfig.SSHPolicy = $sshservice.Policy
    $HostConfig.SSHRunningStatus = $sshservice.Running
    $ntpservice = $vmhost.Config.service.Service | where -property “key” -match “ntpd”
    $HostConfig.NTPRunningStatus = $ntpservice.Running
    $HostConfig.NTPpolicy = $ntpservice.Policy
    $HostConfig.TimeZone = $vmhost.Config.DateTimeInfo.TimeZone.Name
    $HostConfig.NTPServer1 = $vmhost.Config.DateTimeInfo.NtpConfig.Server[0]
    $HostConfig.NTPServer2 = $vmhost.Config.DateTimeInfo.NtpConfig.Server[1]
    $report+=$HostConfig
    }
    IF ($Report -ne “”) {
    $Report | Export-Csv $ExportFilePath -NoTypeInformation
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.