我有一个广告集成的计算机列表,我需要列出他们的最后一次重启时间。 我发现一些像Get-WmiObject -ClassName win32_operatingsystem -ComputerName xxx | select csname, lastbootuptime Get-WmiObject -ClassName win32_operatingsystem -ComputerName xxx | select csname, lastbootuptime但这不是我所需要的。 我需要一个脚本,因为有很多电脑。
我没有PowerShell的经验,如果有人可以帮我一些build议。
PS C:\Users\XxX> Get-wmiobject win32_operatingsystem -ComputerName LC006909 | select csname, @{label='LastRestart';expression={$_.ConverToDateTime($_.LastBootUpTime)}} csname LastRestart ------ ----------- LC006909
我得到这个输出…在LastRestart下是空的。
Nixphoe的答案是绝对正确的,但我想添加如何获取多个计算机的lastbootuptime(输出也可以redirect到一个文件,如果需要):
获取多个机器的最后一次启动时间
$compname = Get-Content -Path C:\computers.txt foreach ($comp in $compname) { Get-WmiObject win32_operatingsystem -ComputerName $comp| select CSName, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}} }
C:\computers.txt – 把计算机主机名放在一行
对我来说,systeminfo真的很慢。 如果你有PowerShell 3,你应该可以使用类似的东西
Get-CimInstance -ComputerName $yourcomputerObj -ClassName win32_operatingsystem | select csname, lastbootuptime
要么
Get-WmiObject win32_operatingsystem -ComputerName $yourcomputerObj | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
链接
有很多方法可以获取最后一次启动时间:
systeminfo | find /i "Boot Time"
会做的伎俩,例如(以可读的格式)。 在这里要注意不同的语言,例如在德国你必须grep“Systemstartzeit”。
你也可以尝试(语言无关的)wmi:
wmic os get lastBootUpTime
这将给你反向格式的启动时间(如20150915100340.494919 + 120)
我总是使用
systeminfo | find "Time"
哪个输出
System Boot Time: 16/09/2015, 08:41:28 Time Zone: (UTC) Dublin, Edinburgh, Lisbon, London