CmdID / PowerShell / Cmdlets / Set
Set-Date
Changes the system time on the computer to a time that you specify. PowerShell reference
From the PowerShell reference 5 parameters
What it does
Changes the system time on the computer to a time that you specify. The Set-Date cmdlet changes the system date and time on the computer to a date and time that you specify. You can specify a new date and/or time by typing a string or by passing a DateTime or TimeSpan object to Set-Date. To specify a new date or time, use the Date parameter. To specify a change interval, use the Adjust parameter. You must have administrative rights to change the system date and time. On Windows, start PowerShell with the Run as administrator option.
Set-Date [-Date] <DateTime> [-DisplayHint <DisplayHintType>] [-WhatIf] [-Confirm] [<CommonParameters>]Set-Date [-Adjust] <TimeSpan> [-DisplayHint <DisplayHintType>] [-WhatIf] [-Confirm] [<CommonParameters>]
Add three days to the system date
Set-Date -Date (Get-Date).AddDays(3)IdentifySet the system clock back 10 minutes
Set-Date -Adjust -0:10:0 -DisplayHint TimeIdentifySet the date and time to a variable value
$T = Get-Date
Set-Date -Date $TIdentifyAdd 90 minutes to the system clock
$90mins = New-TimeSpan -Minutes 90
Set-Date -Adjust $90minsIdentify5: Change to a specific date and time
PS> Get-Date
Monday, June 10, 2024 2:05:48 PM
PS> Set-Date '6/11/2024 2:05:48 PM'
Tuesday, June 11, 2024 2:05:48 PMIdentifyIts page in the reference: Set-Date.
Parameters
-AdjustSpecifies the value for which this cmdlet adds or subtracts from the current date and time. You can type an adjustment in standard date and time format for your locale or use the Adjust parameter to pass a TimeSpan object from New-TimeSpan to Set-Date.-DateChanges the date and time to the specified values. You can type a new date in the short date format and a time in the standard time format for your locale. Or, you can pass a DateTime object from Get-Date.
If you specify a date, but not a time, Set-Date changes the time to midnight on the specified date. If you specify only a time, it doesn't change the date.-DisplayHintSpecifies which elements of the date and time are displayed. The acceptable values for this parameter are:
- Date - displays only the date.
- Time - displays only the time.
- DateTime - displays the date and time.
This parameter affects only the display. It doesn't affect the DateTime object that Get-Date retrieves.-ConfirmPrompts you for confirmation before running the cmdlet.-WhatIfShows what would happen if the cmdlet runs. The cmdlet isn't run.