Powershell Simplified Part 5: Services and EventLogs

Working with Windows services is easy with Powershell.

get-service                    # list of all services
get-service netlogon           # service details
stop-service netlogon -force   # stop a service
start-service netlogon         # start a service

# to view other service related commands use: get-command *-service

Powershell allows manipulating services via WMI too, which we’ll see in another post. Working with the eventlog is also easy.

# get a particular log then filter by source
get-eventLog -logname "Ijv.Platform" -source "Service Control Manager"
# register an event source 'myscript'
new-eventlog -logname application -source myScript 
# write to the eventlog
write-eventlog -logname application -source myScript -entrytype information -eventid 123 -message 'Test event log entry'
get-eventlog -logname application -newest 10         # get top 10 entries
Advertisements

About soumya chattopadhyay
I live and work in Seattle, WA. I work with Microsoft technologies, and I'm especially interested in C#.

One Response to Powershell Simplified Part 5: Services and EventLogs

  1. Pingback: Powershell Simplified Series « I.Net

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: