fortypoundhead.com

Check Remote Services with Powershell

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


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 185 articles.

 


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.80.169.119

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




Recent Forum Posts

Advanced search added
dwirch posted on September 23, 2017 at about 13:44 in Site News

Job Spammer: Gaurav Mehta - AgreeYa Solutions
dwirch posted on September 22, 2017 at about 10:35 in Spammers

Job Spammer: Prutha Siri - Javelin Systems
dwirch posted on September 10, 2017 at about 6:15 in Spammers

New security implemented
dwirch posted on September 7, 2017 at about 7:16 in Site News

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers