一、通过系统命令
cmd:
dir /ah /tw c:\pagefile.sys|findstr .sys
chcp 437
systeminfo | find "System Boot Time:"
systeminfo | findstr /C:"System Boot Time:"
chcp 437
net statistics workstation | find "since"
net stats work | find "since"
2008R2也可以执行net stats srv| find "since"
cmd wmic:
wmic OS GET CSName,LastBootUpTime
powershell:
cmd.exe /c dir /ah /tw c:\pagefile.sys|findstr .sys
Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime
(gcim Win32_OperatingSystem).LastBootUpTime
(gwmi win32_operatingSystem).lastbootuptime
get-date
(get-date) - (gcim Win32_OperatingSystem).LastBootUpTime
((Get-WmiObject Win32_OperatingSystem).ConvertToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime))
$obj = Get-WmiObject Win32_OperatingSystem
$obj.ConvertToDateTime($obj.LastBootUpTime)
$operatingSystem = Get-WmiObject Win32_OperatingSystem
"$((Get-Date) - ([Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime)))"
function Get-SystemUptime {
$operatingSystem = Get-WmiObject Win32_OperatingSystem
"$((Get-Date) - ([Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime)))"
}
Get-SystemUptime
powershell专用命令:
Get-Uptime
Get-Uptime -Since
The Get-Uptime cmdlet was introduced in PowerShell 6.0.
https://learn.microsoft.com/en-US/powershell/module/microsoft.powershell.utility/get-uptime
二、通过第三方工具uptime.exe
https://neosmart.net/uptime/
三、通过微软的小工具uptime.exe
http://web.archive.org/web/20100316211056/http:/download.microsoft.com/download/winntsrv40/install/uptime_1.01/nt4/en-us/uptime.exe
https://networkproguide.com/wp-content/uploads/uptime.zip
https://zedt.eu/storage/2012/uptime.zip
http://web.archive.org/web/20070226103948if_/http://download.microsoft.com:80/download/winntsrv40/install/uptime_1.01/nt4/en-us/uptime.exe
压缩包里有微软1.0.0.1版本、codeplex uptime1.1版本以及https://neosmart.net/uptime/ 的uptime
四、通过事件ID6005的时间点
get-eventlog System | where-object {$_.EventID -eq "6005"} | sort -desc TimeGenerated
Get-WinEvent -ProviderName eventlog | Where-Object {$_.Id -eq 6005 -or $_.Id -eq 6006}
五、通过sysinternals工具psinfo
http://live.sysinternals.com/PsInfo.exe
psinfo.exe -accepteula -nobanner uptime
六、powershell7特有命令
注意:2008R2不支持powershell7(虽然能安装上,但是执行报错)
Get-Uptime -Since