Contact Info

Crumbtrail » Administration » Powershell » Powershell 1.0 » Set-Date

Set-Date - Powershell 1.0 CmdLet

Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. It is designed for system administrators, engineers and developers to control and automate the administration of Windows and applications.

More than hundred command-line tools (so called "cmdlets") can be used to perform system administration tasks and Windows Management Instrumentation (WMI). These cmdlets are easy to use, with standard naming conventions and common parameters, and standard tools for piping, sorting, filtering, and formatting data and objects.


Set system time on the host system


-date DateTime
       Change the date and time to DateTime.
       Pass a Date-Time object from Get-Date or enter a date in  
       the short date format for your locale. 
       The time will default to midnight on the specified date.
       If you specify only a time, the date will not be changed.

   -displayHint DisplayHintType
       Display only the Date, only the Time or the DateTime.
	    This does not affect the DateTime object that is retrieved.

   -adjust TimeSpan
       Add or subtract TimeSpan from the current date and time. 
       Use the standard date and time format for your locale
       or pass a TimeSpan object from New-TimeSpan.
       Describe what would happen if you executed the command without
       actually executing the command.
       Prompt for confirmation before executing the command.

       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Add two days to the current system date, without changing the time:

PS C:\>Set-Date -Date (Get-Date).AddDays(2)

Set the current system time back by 30 minutes:

PS C:\>set-date -adjust -0:30:0

Advance the system time on the local computer forwards by 30 minutes:

PS C:\>$halfhr = new-timespan -minutes 30
PS C:\>set-date -adjust $halfhr