PoshCode Archive  Artifact [8e4647683e]

Artifact 8e4647683ebf9ccd7a99d7c8e94e6773bc0d4c29e6493e736459ad4bc31d44e7:

  • File TimeSyn-HyperV-Settings.ps1 — part of check-in [87a7d51616] at 2018-06-10 13:29:42 on branch trunk — Check Hyper-V Settings for Time Synchronization Status from within a VM Hosted on a Hyper-V Host (user: Vinith Menon size: 1809)

# 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