Domain Time Fix when VM/Hyper-V hosted DCs are involved 2


So I’m part the way through sorting out my new spanky AD on Windows 2012 using Hyper-V and I start to notice time drift.  Not just a little either, we’re slipping minutes a day.

Now usually this would be simple, we just tell the time server master a la PDC emulator to go out the interwebz and grab the time.  Uh Uh Uh, you’re running your PDC emulator on a VM baby and it’s definitely grabbing it’s time from the VM Node.  Okay, we’ll just update the VM Node time via the interwebz then…. Uh Uh Uh, it’s a member of your domain so it’s getting the time from the PDC emulator.

Yup, and so begins the circle of death by W32tm.  Luckily, you can break out the cycle.  Per DC and including the VM Nodes, run this bad boy:

@echo off

cls
echo TIME SOURCE SET
echo ===============
echo.
echo Finding PDC…
:: Retrieve PDC name; delims is a dot, followed by a space and a tab
for /f “tokens=2 delims=. ” %%A IN (‘netdom query /domain:%USERDOMAIN% fsmo 2^>NUL ^| find.exe “PDC”‘) DO SET PDC=%%A
IF NOT DEFINED PDC GOTO NoPdcFound

echo Turning off VM Sync
:: Turn off VM Time
reg add HKLM\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\VMICTimeProvider /v Enabled /t reg_dword /d 0

:: Check if this machine is a PDC
if NOT %COMPUTERNAME%==%%A goto DCTIME
:: PDC Stuff

:: Get time from Internet
echo Setting time server
w32tm /config /manualpeerlist:“0.pool.ntp.org,0x1” /syncfromflags:MANUAL /reliable:yes

:: Set the time
echo Setting the system time
w32tm /config /update w32tm /resync w32tm /resync /rediscover
goto end

:DCTIME
:: Set the time
w32tm /config /update w32tm /resync w32tm /resync /rediscover

:: Check the system
w32tm /query /status
w32tm /query /source

w32tm /config /syncfromflags:DOMHIER /update
net stop w32time
net start w32time
w32tm /resync /force

goto end

:NoPdcFound
echo Cannot find your PDC. Quitting
pause
exit
:end
echo Time services set
pause

From the top, it disables getting time from the VM Node/Host/Hardware.  It finds the PDC and if it is running on it then sets the time source to the internet time keepers.  If not, it sets the time to come from the domain PDC which in turn is getting it’s time from the web time watchers.

Issue cured.


Leave a comment

2 thoughts on “Domain Time Fix when VM/Hyper-V hosted DCs are involved