fortypoundhead.com

Check Remote Services with Powershell

Posted On 2014-08-02 by dwirch
Keywords:
Tags: Scripting Powershell Tip Windows
Views: 2392


If you need to check the status of a service across several machines, and don't have monitoring in place, you can use PowerShell to get Running/Stopped/Starting status quickly.

This one-liner should be of assistance.  I'll pick it apart below.

Get-Service -ComputerName Computer001,Computer002,Computer003,Computer004,Computer005 | Select Name,Status,Machinename | Sort Machinename | Format-Table -autosize

Get-Service
This might come as a surprise: the Get-Service cmdlet is designed to retrieve information about the services installed on your computer or remote computers.  And folks say PowerShell is complicated.


The name of the service that you want status for.  This field also accepts wildcard info.  For example, if you want to see the status of the print spooler, any of these would work:

*spool*
print*
*spooler

-ComputerName
This is the name or names of the remote machines that you want to query for status.  If you enter multiple names, be sure to seperate each by a comma.  Leaving this parameter out will get information from the local machine.

Select name,status,machinename
A pipeline to the select function shows us only the fields we are interested in, the name of the service, current status, and what machine we are querying.

Sort Machinename
Pretty self explanatory, this sorts the output by the name of the remote machine, based on the list given.

Format-Table -autosize
Throw the output in a table, sizing columns automatically.

Run against a text file

You can modify this slightly to read a list of computer names from a file.  That way, you just modify the text file, which contains a list of computer names with one per line, whenever you want to run a check against more machines.

Get-Service -computername (get-content c:\MyDirectory\MyServers.txt) | Select name,status,machinename |sort name | format-table -autosize


About the Author

dwirch has posted a total of 173 articles.

You can find more information from dwirch by visiting http://www.derekwirch.com.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.198.233.27

Before you can post, you need to prove you are human. If you log in, this test goes away.



Recent Forum Posts

Fold Code Manager into main KB?
VB6Boy posted on July 22, 2017 at about 14:42 in Site News

Fold Code Manager into main KB?
dwirch posted on July 22, 2017 at about 14:41 in Site News

Fold Code Manager into main KB?
dwirch posted on July 21, 2017 at about 22:46 in Site News

Fold Code Manager into main KB?
dwirch posted on July 20, 2017 at about 7:55 in Site News

Job Spammer: Sam Mallon
dwirch posted on July 18, 2017 at about 18:36 in Spammers

When setting up a certificate authority ...
dwirch posted on July 13, 2017 at about 9:07 in General