24/7/365 Support

Access Services on a Windows PowerShell Remote Machine

Problem

You want to list or manage services on a remote machine.

Solution

To retrieve the services from a remote machine, use the [System.ServiceProcess. ServiceController]::GetServices() method from the .NET Framework.

PS >[void] ([Reflection.Assembly]::LoadWithPartialName("System.ServiceProcess"))

PS >[System.ServiceProcess.ServiceController]::GetServices("LEEDESK")

Status
Name
DisplayName

Running
ADAM_Test
Test

Stopped
Alerter
Alerter

Running
ALG
Application Layer Gateway Service

Stopped
AppMgmt
Application Management

Stopped
aspnet_state
ASP.NET State Service

Running
AudioSrv
Windows Audio

Running
BITS
Background Intelligent Transfer Ser...

Running
Browser
Computer Browser

Stopped
CiSvc
Indexing Service

To control one, use the WhereObject cmdlet to retrieve that one specifically and then call the methods on the object that manage it:

[void] ([Reflection.Assembly]::LoadWithPartialName("System.ServiceProcess"))

$service = [System.ServiceProcess.ServiceController]::GetServices("LEEDESK") | WhereObject { $_.Name eq "Themes" }

$service.Stop() $service.WaitForStatus("Stopped") StartSleep 2 $service.Start()

Discussion

If you have administrator privileges on a remote machine, the [System. ServiceProcess.ServiceController]::GetServices() method from the .NET Framework lets you control services on that machine.

When doing this, note that both of the examples from the solution require that you first load the assembly that contains the .NET classes that manage services. The *Service cmdlets load this DLL automati

cally.

Help Category:

Get Windows Dedicated Server

Only reading will not help you, you have to practice it! So get it now.

Processor RAM Storage Server Detail
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 128 GB (SSD SATA) Configure Server
Intel Atom C2750 2.4 GHz 8c/8t 8 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Xeon E3-1230 v2 3.3 GHz 4c/8t 16 GB DDR3 1× 256 GB (SSD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 250 GB (SSD SATA) Configure Server

What Our Clients Say