我想在我的脚本中的各个位置输出日期时间以进行日志记录,所以我这样做:
$b = Get-Date
Write-Output "Backups complete at $b"
# more code here
$c = Get-Date
Write-Output "Backups complete at $c"
我不得不使用多个字母来获取最新的日期/时间。
有没有更简单的方法来做到这一点,还是每次我想再次使用它时都必须重新建立日期?
最佳答案
将当前日期时间分配给变量后,您将捕获运行时的日期和时间 Get-Date
.
每次需要新的日期和时间时,都需要再次运行它。您可以避免使用变量:
Write-Output "Backups complete at $(Get-Date)"
关于powershell - 在 PowerShell 中输出日期/时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38513806/