I have a small script for a work computer and I would like to add a command that is run at a specific time.
Since this is a work computer, I cant use Task Scheduler due to permissions.
Found this script that can restart the computer at 8PM.
If you're looking to start a script and have it wait for the desired time to act, then you could use a combination of Get-Date and Start-Sleep. Then it would just run whatever commands you want. In the script you quote, the Shutdown command has a wait parameter built in, but you could replicate that with Start-Sleep
That's that works great, anyway to prevent the command from running after the set time?
So if I restart the script it wont run till the next time as currently it is giving me an error about the time being below 0.
The script above prevents a work computer from going to the lock screen.
Head office wants the computer to go to sleep for secrurity reasons but since this computer will not be used for several minutes even if were in front of it, it locks out, so getting back to work can take minutes due to the user profile being online.