# encoding: ascii
# api: powershell
# title: TimeSyn HyperV Settings
# description: Check Hyper-V Settings for Time Synchronization Status from within a VM Hosted on a Hyper-V Host
# version: 0.1
# type: class
# author: Vinith Menon
# license: CC0
# x-poshcode-id: 3708
# x-archived: 2012-10-26T14:50:57
# x-published: 2012-10-22T21:20:00
#
# http://powershell-enthusiast.blogspot.in/2012/10/check-hyper-v-settings-for-time.html
#
<#Time Synchronization Status#>
	
	Write-Host "Time Synchronization Status" -ForegroundColor Yellow
	Write-Host "_______________________________" -ForegroundColor Yellow
	Write-Host
	
	$VMhost = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters" | select -ExpandProperty physicalhostname
	$VirtualMachineName = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters" | select -ExpandProperty VirtualMachineName
	$session = New-PSSession -ComputerName $vmhost
	Invoke-Command -Session $session {
	param($vmname)
	$MgmtSvc = gwmi -namespace root\virtualization MSVM_VirtualSystemManagementService
	$VM = gwmi -namespace root\virtualization MSVM_ComputerSystem |?{$_.elementname -match $vmname}
	$TimeSyncComponent = gwmi -query "associators of {$VM} where ResultClass = Msvm_TimeSyncComponent" -namespace root\virtualization                
	$TimeSyncSetting  = gwmi -query "associators of {$TimeSyncComponent} where ResultClass = Msvm_TimeSyncComponentSettingData" -namespace root\virtualization                
	# Disable = 3; Enable = 2        
	if ($TimeSyncSetting.EnabledState -eq 3 ){
	Write-Host "Time Synchronzation Disabled"  -ForegroundColor Green 
	}
	else{ Write-Host "Time Synchronzation Enabled" -ForegroundColor Red }
	} -Args $VirtualMachineName
	Get-PSSession | Remove-PSSession
