執行指令
PS C:\> $a=(Get-WmiObject -Class Win32_OperatingSystem).LastBootUpTime
PS C:\> $b = New-TimeSpan $(Get-Date –month $a.substring(4,2) -day $a.substring(6,2) -year $a.substring(0,4) -hour $a.substring(8,2) -minute $a.substring(10,2) ) $(Get-Date)
PS C:\> $b


執行結果
Days : 0
Hours : 2
Minutes : 26
Seconds : 3
Milliseconds : 671
Ticks : 87636718720
TotalDays : 0.101431387407407
TotalHours : 2.43435329777778
TotalMinutes : 146.061197866667
TotalSeconds : 8763.671872
TotalMillise$conds : 8763671.872




[新寫法]
PS C:\> New-TimeSpan $(Get-Date ((Get-WmiObject -Class Win32_OperatingSystem).LastBootUpTime -replace '(....)(..)(..)(..)(..)(..)(.*)','$1/$2/$3 $4:$5:$6')) $(Get-Date)

[20080822]
Scripting Guy的寫法

arrow
arrow
    全站熱搜

    ayowu 發表在 痞客邦 留言(0) 人氣()