Powershell - Set System Time



Cmdlet

Set-Date cmdlet is used to set System Time.

In this example, we're using Get-Date to get current date

Type the following command in PowerShell ISE Console

get-date -displayHint time

Output

You can see following output in PowerShell console.

10:04:18 AM

In this example, we're using Set-Date to adjust to 60 minutes.

Type the following commands in PowerShell ISE Console

> $timeToAdd = New-TimeSpan -Minutes -60
> set-date -adjust $timeToAdd

Output

You can see following output in PowerShell console.

Saturday, May 05, 2018 11:05:16 AM

Now revert back to substract added time to current date.

Type the following command in PowerShell ISE Console

> $timeToAdd = New-TimeSpan -Minutes -60
> set-date -adjust $timeToAdd

Output

You can see following output in PowerShell console.

Saturday, May 05, 2018 10:08:54 AM
powershell_dates_timers.htm
Advertisements