Well, I know what you’re thinking, it is just click bait. But I want to assure you it is possible.
You could create this into a function but the magic is in the details of this one.
“New-TimeSpan” is a tool that has existed since 2.0 and before you start-sleep ever again, consider the possibilities if you can truly calculate the duration of start-sleep dynamically!
So I stumbled across this only due to the need to simulate a scheduled task/job quickly in an environment I had not the local privileges to ensure that I could create a scheduled job.
If necessary you could utilize this to create some uniformity in your daily duties, reminders, etc.
So Let’s see this tag team with Start-Sleep!
I included the variable to display how this works so well. you just define when you want the script to stop that same day. It will show an error if you did it differently. However, as long as the values are a positive number and not a negative integer you have a timespan.
The last example is using it to control things in the future….essentially a PowerShell Time machine, please share any of your experiences in the comments or on Twitter.
so just know that time only flows in one direction. Trying to relive the past can cause you errors lol. Kind of ironic how that works outside the shell too. Don’t forget to visit other parts of the city. See ya around, and avoid cyclic redundancy errors!