Link to home
Start Free TrialLog in
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?
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Better to use the matching operator of the cmdlet itself:
Get-Service -ComputerName MyServer -Name "FINANCE SERVICE 1" | Restart-Service

Open in new window

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

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