一、通过系统命令
cmd:
代码语言:javascript复制dir /ah /tw c:pagefile.sys|findstr .sys
代码语言:javascript复制chcp 437
systeminfo | find "System Boot Time:"
systeminfo | findstr /C:"System Boot Time:"
代码语言:javascript复制chcp 437
net statistics workstation | find "since"
net stats work | find "since"
2008R2也可以执行net stats srv| find "since"
cmd wmic:
代码语言:javascript复制wmic OS GET CSName,LastBootUpTime
powershell:
代码语言:javascript复制cmd.exe /c dir /ah /tw c:pagefile.sys|findstr .sys
代码语言:javascript复制Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime
代码语言:javascript复制(gcim Win32_OperatingSystem).LastBootUpTime
(gwmi win32_operatingSystem).lastbootuptime
代码语言:javascript复制get-date
(get-date) - (gcim Win32_OperatingSystem).LastBootUpTime
代码语言:javascript复制((Get-WmiObject Win32_OperatingSystem).ConvertToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime))
代码语言:javascript复制$obj = Get-WmiObject Win32_OperatingSystem
$obj.ConvertToDateTime($obj.LastBootUpTime)
代码语言:javascript复制$operatingSystem = Get-WmiObject Win32_OperatingSystem
"$((Get-Date) - ([Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime)))"
代码语言:javascript复制function Get-SystemUptime {
$operatingSystem = Get-WmiObject Win32_OperatingSystem
"$((Get-Date) - ([Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime)))"
}
Get-SystemUptime
powershell专用命令:
代码语言:javascript复制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
代码语言:javascript复制https://neosmart.net/uptime/
三、通过微软的小工具uptime.exe
代码语言:javascript复制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的时间点
代码语言:javascript复制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
代码语言:javascript复制http://live.sysinternals.com/PsInfo.exe
代码语言:javascript复制psinfo.exe -accepteula -nobanner uptime
六、powershell7特有命令
注意:2008R2不支持powershell7(虽然能安装上,但是执行报错)
https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7
https://learn.microsoft.com/zh-cn/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7
Differences between Windows PowerShell 5.1 and PowerShell 7.x
https://learn.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7
https://learn.microsoft.com/zh-cn/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7
代码语言:javascript复制Get-Uptime -Since
参考:
代码语言:javascript复制https://stackoverflow.com/questions/11606774/how-to-get-the-system-uptime-in-windows
https://networkproguide.com/how-to-check-windows-server-uptime/
https://www.nextofwindows.com/how-long-my-computer-has-been-running-get-to-know-my-computers-uptime
https://blog.csdn.net/CHCH998/article/details/107178906
https://www.windows-commandline.com/windows-last-boot-time