【发布时间】:2018-01-03 18:33:16
【问题描述】:
我正在尝试仅从 PowerShell 脚本中检索日期和时间,以下是我迄今为止尝试过的:
脚本:
NET TIME \\ComputerName | Out-File $location
(Get-Content $location) | % {
if ($_ -match "2018 : (.*)") {
$name = $matches[1]
echo $name
}
}
net time 输出如下:
我只需要当地时间“11:05”的部分。
【问题讨论】:
-
为什么需要这样做?您的计算机没有与附近的域控制器同步时钟吗?
-
我需要这个来执行另一个命令“Dumplog”,它只需要开始时间和结束时间作为参数。命令:dumplog ctisvr /bt "Local time" /m "CSTAUniversalFailureConfEvent" 因此我需要服务器的本地时间运行最后 5 分钟。
标签: regex windows powershell time ob-get-contents