如果我是Linux,我可以uptime
用来获取诸如此类的信息
PowerShell可以做到这一点吗?
仅使用PowerShell,对此有一些不同的看法。以本文为基础:
New-TimeSpan -Start (Get-CimInstance -ClassName win32_operatingsystem).LastBootUpTime -End (Get-Date)
此链接还显示了如何根据需要使用Get-WMIObject。
这个有点长.....
New-TimeSpan -Start ((Get-WmiObject win32_operatingsystem | `
Select-Object @{Name='LastBootUptime';Expression={$_.ConverttoDateTime($_.lastbootuptime)}}).lastbootuptime) -End (Get-Date)
从那里,您可以将对象格式化为不包含毫秒等。
例如:
New-TimeSpan -Start (Get-CimInstance -ClassName win32_operatingsystem).LastBootUpTime -End (Get-Date) | `
Select-Object Days,Hours
谢谢,蒂姆。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句