Avatar of kam_uk
 asked on

Check status of remote services using Powershell


I have a couple of Windows 2008 R2 servers running an app named FINANCE. There is a service on there named "FINANCE SERVICE 1" that I need to restart sometimes.

Since I've got a Windows 2008 R2 'admin' server, I'd like to be able to use Powershell to

i. Find out the status of "FINANCE SERVICE 1" on a given machine
ii. Start, stop or restart that service if I need

Is this possible?
Windows Server 2008Powershell

Avatar of undefined
Last Comment
Ciprian Lozonschi

8/22/2022 - Mon
David Johnson, CD

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Better to use the matching operator of the cmdlet itself:
Get-Service -ComputerName MyServer -Name "FINANCE SERVICE 1" | Restart-Service

Open in new window

Ciprian Lozonschi

Never use Restart-Service, it will do this on local machine because it down't have remote capabilities. This is a mistake a lot of people are doing
To restart a service use WMI instead.

(Get-WmiObject -ComputerName server_name -Class Win32_Service -Filter "name='FINANCE SERVICE 1'").StartService()

Open in new window


That's true, of all *-service cmdlets only get-service and set-service allow for a ComputerName. Stupid implementation.
However, restarting a service consists of stopping and starting, not only starting, so we would have to do something like:
gwmi Win32_Service -ComputerName server_name -Filter "name='FINANCE SERVICE 1'" | % {$_.StopService(); $_.StartService()} | out-null

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Ciprian Lozonschi

I was just commenting on the restart part. Now I see I used there StartService(), even I was thingking to stop and them start service.

Qlemo your point is good