获取系统开机时间

有时为了计算服务器运行时长,需要获取系统开机时间。
 
   1:  $RunTime = (Get-WmiObject -Class Win32_OperatingSystem -Namespace root\CIMV2).lastbootuptime
   2:  $Year = $RunTime.Substring(0,4)
   3:  $Month = $Runtime.Substring(4,2)
   4:  $Day = $Runtime.Substring(6,2)
   5:  $Hour = $Runtime.Substring(8,2)
   6:  $Min = $Runtime.Substring(10,2)
   7:  $Sec = $Runtime.Substring(12,2)
   8:  $RunTimeS = $Year + "-" + $Month + "-" + $Day + " " + $Hour + ":" + $Min + ":" + $Sec
   9:  $StartTime = [system.Convert]::ToDateTime($RunTimeS)
  10:  Write-Host "系统开机时间为:"$StartTime
posted @ 2013-08-26 09:33  motools  阅读(660)  评论(0编辑  收藏  举报