FreeKB - PowerShell Get-Date command
PowerShell - Get-Date command

Using the date function in PowerShell is easy. To get started, use the following to display today's date:

$date = (Get-Date).ToString('MM/dd/yyyy')
write-host $date


You probably want to include the date in another string, like this:

$date = (Get-Date).ToString('MM/dd/yyyy')
$today = "Today's date is $date."

write-host $today


The previous examples work's great because there is a space after the word "is" and before the $date function. However, if there are no spaces, we need to put the date function in parenthesis.

$date = (Get-Date).ToString('MM/dd/yyyy')
$file= "Here is the file you requested: example$($date).pdf"

write-host $file


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter f271d in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |