fortypoundhead.com

Check Remote Services with Powershell

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


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 172 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.211.79.150

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



Recent Forum Posts

Job Spammer: Sathya Narayana
dwirch posted on March 15, 2017 at about 7:18 in Spammers

Job Spammer: Manish Kumar
dwirch posted on March 14, 2017 at about 17:44 in Spammers

Site Migration Complete
dwirch posted on March 12, 2017 at about 11:10 in Site News

Site Migration Complete
dwirch posted on March 11, 2017 at about 0:35 in Site News

Job Spammer: Jason Weinstein
dwirch posted on March 10, 2017 at about 14:00 in Spammers

Job Spammer: Ryan Wilson
dwirch posted on March 8, 2017 at about 17:00 in Spammers