Search Tools Links Login

Check Remote Services with Powershell


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 this post

Posted: 2014-08-02
By: dwirch
Viewed: 6,502 times

Categories

Tip

Scripting

Powershell

Windows

PowerShell Code Cache

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.