系统运行时间 5


.SYNOPSIS Run-Time.ps1 - 系统运行时长.
.NOTES Written By: Sam Lu .
.Change Log V1.0, 25/07/2013 - 测试版
$start = (Get-Process wininit).StartTime
$end = Get-Date
$runtime = New-TimeSpan -Start $start -End $end
$rundays = $runtime.Days
$runhours = $runtime.Hours
$runmin = $runtime.Minutes
Write-Host “开机时间为: $start ”
Write-Host "您的系统已经运行了 $rundays 天 $runhours 小时 $runmin 分钟"

在各位指引下改进下次程序

$RunTime = (Get-WmiObject -Class Win32_OperatingSystem -Namespace root\CIMV2).lastbootuptime
$Year = $RunTime.Substring(0,4)
$Month = $Runtime.Substring(4,2)
$Day = $Runtime.Substring(6,2)
$Hour = $Runtime.Substring(8,2)
$Min = $Runtime.Substring(10,2)
$Sec = $Runtime.Substring(12,2)
$RunTimeS = $Year + "-" + $Month + "-" + $Day + " " + $Hour + ":" + $Min + ":" + $Sec
$StartTime = [system.Convert]::ToDateTime($RunTimeS)
Write-Host "系统开机时间为:"$StartTime 

×用微信扫描并分享
本文链接: https://www.pstips.net/system-running-time.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

motools进行回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

5 条评论 “系统运行时间