English

Checking the last time a service stopped or started on Windows

This is the two easy ways to find start time and stop time for a windows service in PowerShell.

#1: Search within the Windows Event Logs

A new entry is added to the System Event Logs every time the service changes. The script can take some time depending on how big is your Event Logs and the info could have disappeared if it’s too old.

However, you can find the start time with -Message “*LanmanServer*running*” and the stopped time with -Message “*LanmanServer*stopped*”.

(Get-EventLog -LogName "System" -Source "Service Control Manager" -EntryType "Information" -Message "*LanmanServer*running*" -Newest 1).TimeGenerated

#2: Search the start time with the process id

This script is fast but can only find the start time as it is based on a running process.

Get-Process | select name, id, starttime | Select-String (Get-WmiObject -Class Win32_Service -Filter "Name LIKE 'LanmanServer'" | Select-Object -ExpandProperty ProcessId)
(Get-WmiObject -Class Win32_Service -Filter "Name LIKE 'LanmanServer'" | Select-Object -ExpandProperty ProcessId)

0 comments on “Checking the last time a service stopped or started on Windows

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: