-1
I can't program one line in PowerShell (I'm a linux user...). For a dev PC/Server with Windows on it, I need it to be always on one specific date (1.3.2017). Because it's a vmware vm the vm-supervisor sometimes resyncs the real time after freezing/snapshotting etc.
There are specific settings in the vmware supervisor, but they have no effect.
Is there a way to have it check whether the date is set on another day and set it to 1.3.2017 if neccesary?
I would want to do this every minute or so (I assume there is a cron-equivalent on windows).
1To remove the
HHmmss
part enclose the datetime in parentheses and append ().Date. -->$Date_To_Set = (Get-Date -Day 01 -Month 03 -Year 2017).Date
2nd line -->if ((Get-Date).Date -ne $Date_To_Set){ $Date_To_Set | Set-Date }
The representation order of date elements doesn't matter for type datetime. – LotPings – 2018-10-04T16:13:08.437Thank you very much! It works!
Is there any way to preserve the time? – philipp – 2018-10-05T07:01:03.950
Script has been updated to preserve the time as requested. – CraftyB – 2018-10-05T08:49:32.057