One way to change the date/time on a computer is to use the -date parameter followed by the new date and time. For example, suppose you want to set the date and time to 1:11 AM on June 6, 2015. Here’s how you do that:
1 |
Set-Date -date "6/6/2015 1:11 AM" |
Need to set the clock ahead exactly two days? This command uses the Get-Date cmdlet and the AddDays method to advance the clock two days:
1 |
Set-Date (Get-Date).AddDays(2) |
Other methods that can be used here include AddHours, AddMinutes, and AddSeconds. Need to set the clock back 1 hour due to Daylight Saving Time? Then simply set the clock back -1 (minus 1) hours, like this:
1 |
Set-Date (Get-Date).AddHours(-1) |
Alternatively, you can use the -adjust parameter to adjust the time using the format hours:minutes:seconds. For example, this command sets the clock ahead 1 hour and 11 minutes
1 |
Set-Date -adjust 1:11:11 |