Output the date/time in PowerShell

Once you assign the current datetime to a variable, you are capturing the date and time at the moment you ran Get-Date.

Every time you want a new date and time, you need to run it again. You could avoid using a variable:

Write-Output "Backups complete at $(Get-Date)"

Leave a Comment