Thursday 11 August 2011

Checks hosts with NTP service stopped

#Description: This function checks hosts with NTP service stopped
#Purpose: NTP required to keep correct time for VMs and hosts
#Designed to be added as function into $profile for quick-admin tasks, run from commandline


#Requires VCLI snapin - www.vmware.com/support/developer/vcli/
#Author: Kirk Munro, extracted from VMware powerpack: http://www.powergui.org/entry.jspa?externalID=1802&categoryID=290
#Tested with: ESX4.1
#Last edit by: MsMiller on 11/08/2011

function func_Hosts_with_NTP_Service_Stopped()
{
$noConnection = $true
if ($defaultVIServers) {
 foreach ($managedHost in $defaultVIServers) {
  $noConnection = $false
  Get-VMHost -Server $managedHost | ForEach-Object {
   $vmhost = $_.Name
   $_ | Get-VMHostService | Where {($_.key -eq "ntpd") -and ($_.Running -eq $false)} | ForEach-Object {
    $_.PSObject.TypeNames.Insert(0,"$($_.PSObject.TypeNames[0])#VmwarePowerPackExtension")
    $_ `
     | Add-Member -MemberType NoteProperty -Name VMHost -Value $vmhost -PassThru `
     | Add-Member -MemberType NoteProperty -Name ManagedHost -Value $managedHost.Name -PassThru
   }
  }
 }
}
if ($noConnection){
 Show-MessageBox -Text 'You must connect to one or more vSphere servers before you can run the Hosts with NTP Service best practice query on those servers. Please click on the ''Managed Hosts'' node, connect to one or more of the vSphere servers you have configured there, and then try again.' -Caption 'Connection not established' -Buttons 'OK' -Icon 'Information' | Out-Null
}
}


 func_Hosts_with_NTP_Service_Stopped | Select-Object -property 'VMHost', 'Key', 'Label', 'Policy', 'Running', 'Required'