Cmd/PowerShell/SQL server: Is there any way to see how long a windows service has been running?

三世轮回 提交于 2019-12-04 20:13:57

As long as your service has it's own process name, this should work.

PowerShell_v4> (Get-Process lync).StartTime

Friday, October 17, 2014 11:46:04

If you're running under svchost.exe, i think you need to grab that from Event Log.

PowerShell_v4> (Get-WinEvent -LogName System | ? Message -match 'DHCPv6 client service is started' | select -First 1).TimeCreated

Friday, October 17, 2014 10:10:56

For Uptime, just compute time diff.

$Start = (Get-Process Outlook).StartTime
$Now = Get-Date
$Now - $Start | Format-Table Days, Hours, Minutes, Seconds -AutoSize

Days Hours Minutes Seconds
---- ----- ------- -------
   0     0       2       8

or as a one-liner:

(Get-Date) - (Get-Process Outlook).StartTime | Format-Table Days, Hours, Minutes, Seconds -AutoSize

Days Hours Minutes Seconds
---- ----- ------- -------
   0     0       2       8
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!