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

-Alan

Alan

Alan Renouf has a role of Automation Frameworks Product Manager at VMware responsible for providing the architects and operators of the cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/vipowershell and has a personal blog at http://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

You may also like...

2 Responses

  1. Yannick says:

    Thanks Alan

  2. Sanshis says:

    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

%d bloggers like this: