Get-EventLog -LogName System -InstanceId 6006 -newest 1
要仅获取日期,请执行以下操作:
(Get-EventLog -LogName System -InstanceId 6006 -newest 1).timeGenerated
要以所需格式获取日期(根据需要进行修改):
get-date((Get-EventLog -LogName System -InstanceId 6006 -newest 1).timeGenerated) -format yyyyMMdd
要从cmd执行它,请执行以下操作:
powershell get-date((Get-EventLog -LogName System -InstanceId 6006 -newest 1).timeGenerated) -format yyyyMMdd
cmd获取命令输出的方法是for(您需要在命令中避开关闭偏执):
for /f "delims=" %%a in ('powershell get-date((Get-EventLog -LogName System -InstanceId 158 -newest 1^).timeGenerated^) -format yyyyMMdd') do set lastShutdown=%%a
# 1 楼答案
Powershell有一种获取上次关机日期和时间的简单方法:
要仅获取日期,请执行以下操作:
要以所需格式获取日期(根据需要进行修改):
要从
cmd
执行它,请执行以下操作:cmd
获取命令输出的方法是for
(您需要在命令中避开关闭偏执):(注意:
%%a
语法用于批处理文件。若要直接从命令行使用它,请仅使用单个%
:%a
)