PowerShell/Windowsの起動時刻の取得と稼働時間の取得
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* Windowsの起動時刻の取得と稼働時間の取得方法 [#sd3b3aa5]
PowerShellを使って、Windowsの起動時刻と稼働時間を取得する...
Linuxなどでは、uptimeコマンドの稼働時間取得と似ています。
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
*関連記事 [#e38ec2a7]
-[[PowerShellでuptimeファンクションを作ってみた>PowerShel...
* 起動時刻の取得 [#r53f9533]
PowerShellを起動して、以下のコマンドを実行するとWindowsを...
(Get-WmiObject Win32_OperatingSystem).LastBootUpTime
実行例
PS C:\> (Get-WmiObject Win32_OperatingSystem).LastBootUp...
20160101214117.495750+540
これでは並んでわかりづらいので変換して表示してみます。
[Management.ManagementDateTimeConverter]::ToDateTime((Ge...
実行例
PS C:\> [Management.ManagementDateTimeConverter]::ToDate...
2016年1月1日 21:41:17
尚、取得した起動時間のオブジェクトは以下のようにDateTime...
PS C:\Users\sakura> $boottime=( [Management.ManagementDa...
PS C:\Users\sakura> $boottime.GetType()
IsPublic IsSerial Name ...
-------- -------- ---- ...
True True DateTime ...
PS C:\Users\sakura> "$($boottime.Year)/$($boottime.Month...
2016/1/4 22:0:8
&color(red){注意};~
このLastBootUpTimeの値は、systeminfoコマンドで取得できる...
Windows10で上記PowerShellコマンドおよびsysteminfoコマンド...
シャットダウンしても起動したままになっている模様である。~
再起動すれば、起動時間は変更(リセット)されているのが確認...
> systeminfo
<snip>
システム起動時間: 2016/01/01, 21:41:17
<snip>
* 稼働時間を取得する [#yb9baf50]
Linuxのuptimeコマンドが表示する、稼働時間をPowerShellを使...
現在時刻から上記の起動時間を引き算して求める。
[DateTime]::Now - [Management.ManagementDateTimeConverte...
または
(Get-Date) - [Management.ManagementDateTimeConverter]::T...
実行例
PS C:\Users\sakura> [DateTime]::Now - [Management.Manage...
Days : 0
Hours : 0
Minutes : 10
Seconds : 5
Milliseconds : 758
Ticks : 6057585232
TotalDays : 0.00701109401851852
TotalHours : 0.168266256444444
TotalMinutes : 10.0959753866667
TotalSeconds : 605.7585232
TotalMilliseconds : 605758.5232
これでは見にくいので、以下のようにすればよいでしょう。
PS C:\Users\sakura> (Get-Date) - [Management.ManagementD...
Days Hours Minutes Seconds Milliseconds
---- ----- ------- ------- ------------
0 0 15 29 152
または
PS C:\Users\sakura> $boottime=( [Management.ManagementDa...
PS C:\Users\sakura> (Get-Date) - $boottime | Select-Obje...
Days Hours Minutes Seconds
---- ----- ------- -------
0 0 16 36
* GUIにて確認する [#je21073c]
Windows8.1やWindows10などであれば、タスクマネージャの画面...
#ref(01.png)
以上、WindowsのPowerShellを使って、起動時間と稼働時間を取...
#htmlinsertpcsp(win-btm.html,win-sp.html)
終了行:
#navi(../)
* Windowsの起動時刻の取得と稼働時間の取得方法 [#sd3b3aa5]
PowerShellを使って、Windowsの起動時刻と稼働時間を取得する...
Linuxなどでは、uptimeコマンドの稼働時間取得と似ています。
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
*関連記事 [#e38ec2a7]
-[[PowerShellでuptimeファンクションを作ってみた>PowerShel...
* 起動時刻の取得 [#r53f9533]
PowerShellを起動して、以下のコマンドを実行するとWindowsを...
(Get-WmiObject Win32_OperatingSystem).LastBootUpTime
実行例
PS C:\> (Get-WmiObject Win32_OperatingSystem).LastBootUp...
20160101214117.495750+540
これでは並んでわかりづらいので変換して表示してみます。
[Management.ManagementDateTimeConverter]::ToDateTime((Ge...
実行例
PS C:\> [Management.ManagementDateTimeConverter]::ToDate...
2016年1月1日 21:41:17
尚、取得した起動時間のオブジェクトは以下のようにDateTime...
PS C:\Users\sakura> $boottime=( [Management.ManagementDa...
PS C:\Users\sakura> $boottime.GetType()
IsPublic IsSerial Name ...
-------- -------- ---- ...
True True DateTime ...
PS C:\Users\sakura> "$($boottime.Year)/$($boottime.Month...
2016/1/4 22:0:8
&color(red){注意};~
このLastBootUpTimeの値は、systeminfoコマンドで取得できる...
Windows10で上記PowerShellコマンドおよびsysteminfoコマンド...
シャットダウンしても起動したままになっている模様である。~
再起動すれば、起動時間は変更(リセット)されているのが確認...
> systeminfo
<snip>
システム起動時間: 2016/01/01, 21:41:17
<snip>
* 稼働時間を取得する [#yb9baf50]
Linuxのuptimeコマンドが表示する、稼働時間をPowerShellを使...
現在時刻から上記の起動時間を引き算して求める。
[DateTime]::Now - [Management.ManagementDateTimeConverte...
または
(Get-Date) - [Management.ManagementDateTimeConverter]::T...
実行例
PS C:\Users\sakura> [DateTime]::Now - [Management.Manage...
Days : 0
Hours : 0
Minutes : 10
Seconds : 5
Milliseconds : 758
Ticks : 6057585232
TotalDays : 0.00701109401851852
TotalHours : 0.168266256444444
TotalMinutes : 10.0959753866667
TotalSeconds : 605.7585232
TotalMilliseconds : 605758.5232
これでは見にくいので、以下のようにすればよいでしょう。
PS C:\Users\sakura> (Get-Date) - [Management.ManagementD...
Days Hours Minutes Seconds Milliseconds
---- ----- ------- ------- ------------
0 0 15 29 152
または
PS C:\Users\sakura> $boottime=( [Management.ManagementDa...
PS C:\Users\sakura> (Get-Date) - $boottime | Select-Obje...
Days Hours Minutes Seconds
---- ----- ------- -------
0 0 16 36
* GUIにて確認する [#je21073c]
Windows8.1やWindows10などであれば、タスクマネージャの画面...
#ref(01.png)
以上、WindowsのPowerShellを使って、起動時間と稼働時間を取...
#htmlinsertpcsp(win-btm.html,win-sp.html)
ページ名: