1

Complete newbie to powershell and scripting, here.

I have figured out how to set date and time through powershell using the set-date cmdlet.

However, I can't figure out how to execute the script with admin rights before Windows logon or anyway as soon as possible in the boot process.

(I need to keep a VM frozen in time, however it seems that Hyper-V doesn't really honor the time sync settings, or Windows has a way around it. Just in case: yes, I also disabled automatic time sync within Windows and even blocked time.windows.com through the hosts file just in case)

Any hints? Thanks

0

You're misunderstanding what the Hyper-V Time Synchronization Integration Service does and how it operates. If enabled, it syncs the guest time to the host while the guest is running. It has no bearing on the guest when the guest is off. On startup, the guest gets it's time directly from the Hyper-V host, not from the integration service. If you want to "freeze" the guest time then you need to put the guest into a saved state. When you restore the guest from the saved state it's time will be the time at which you saved it.

| improve this answer | |
  • Hi, I am aware the Time Synchronization will be effective while the guest is running. This is, in fact, why I wondered how the time got synchronized given I disabled the Time Synchronization Integration Service. Odd that no option was included to disable the initial sync with the host. Moreover, to my experience even restoring a state will result in time being set to the current's host date and time. Perhaps using "Standard" snapshots rather than "Production" snapshots will change that? – resle Jan 24 '18 at 7:39
  • I'm not referring to snapshots or checkpoints, I'm referring to saving the guest. Right click the guest in the Hyper-V Manager console and select "Save". This will effectively "freeze" the state of the guest, including the time. When you "restore" the guest from the saved state it's time will be the time at which you "froze" it. – joeqwerty Jan 24 '18 at 12:12
  • Thanks for the hint. However the problem stands: after restoring the savestate, after a while the machine time gets synchronized. This is really odd, I even set a fake proxy on the guest to make sure it can't connect to any ntp server for any reason. – resle Jan 24 '18 at 12:45
0

I managed to set the date at logon in this way:

schtasks /create /tn "Set Date" /tr c:\setdate.bat /sc onstart /ru SYSTEM

With a trivial batch file that... sets the date.

However I have found something way more interesting. As I said, the system kept synchronizing the date somehow, and I couldn't figure out how and why.

The final solution was:

  • run secpol.msc (local security policy console)
  • local policies -> security options -> user rights assignment
  • remove all users including LOCAL SERVICE from "change the system time"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.