English
+(370) 5 205 5502 sales@monovm.com

At MonoVM we provide you with the underlying facts, assumptions and rules which a computer system has.

10

Apr, 19

Managing Windows services with PowerShell

PowerShell is a task automation and configuration management framework from Microsoft. Today we will familiarize you with how to manage Windows services through PowerShell as it is much quicker and more efficient than other methods.

As you may know, one of the most important parts of each operating system is the service which runs through it, and in general, it can be said that every part of the operating system that starts has a specific service that can be managed and controlled.

Here's a detailed tutorial on how to use PowerShell to manage Windows services.

  • Run a PowerShell terminal with Administrator access

 Service Managment with powerShell 1

At first, you must get a list of available services using the following command:

Get-Service

This is a sample of the output you'll receive.

PS C:\Users\Administrator> Get-Service

 

Status   Name               Display Name

------   ----               -----------

Running  AcrSch2Svc         Acronis Scheduler2 Service

Running  AdobeUpdateService AdobeUpdateService

Running  afcdpsrv           Acronis Nonstop Backup Service

Running  AGMService         Adobe Genuine Monitor Service

Running  AGSService         Adobe Genuine Software Integrity Se...

Stopped  AJRouter           AllJoyn Router Service

Stopped  ALG                Application Layer Gateway Service

Running  AMD External Ev... AMD External Events Utility

Stopped  AppIDSvc           Application Identity

Stopped  Appinfo            Application Information

Stopped  AppMgmt            Application Management

Stopped  AppReadiness       App Readiness

Stopped  AppVClient         Microsoft App-V Client

Stopped  AppXSvc            AppX Deployment Service (AppXSVC)

Stopped  AssignedAccessM... AssignedAccessManager Service

Running  AudioEndpointBu... Windows Audio Endpoint Builder

Running  Audiosrv           Windows Audio

Stopped  AxInstSV           ActiveX Installer (AxInstSV)

Stopped  BcastDVRUserSer... GameDVR and Broadcast User Service_...

Stopped  BDESVC             BitLocker Drive Encryption Service

Running  BFE                Base Filtering Engine

Running  BITS               Background Intelligent Transfer Ser...

Stopped  BluetoothUserSe... Bluetooth User Support Service_24d986

In the output, by default, you will see 3 main sections: Status, Name and Display Name.

Now, if you want to search and list a particular service, you can filter out any of the parameters.

For example:

  • Show all services whose names start with wi:

Get-Service -Name wi*

  • Show all services whose display names start with win:

Get-Service -DisplayName win*

  • Note: If you want to access another computer through the network, you can see the list of services for that system with this command:

Get-Service -ComputerName Server1

An important part of service management is management of Dependent Services.

  • To access the Dependency Services list for a specific service we can use the following command:

Get-Service -Name WinDefend -DependentServices

  • You can also use the Required Services parameter to get a list of service pre-requisites.

Get-Service -Name WinDefend - RequiredServices

So with the above commands, we can find the name of the service we are looking for, see the status and related services or its prerequisites. Now we want to explain the services’ management commands.

  • For stopping a service with PowerShell you can use the following command:

Stop-Service -Name Windefend

  • For starting a service in PowerShell you can use this command:

Start-Service -Name Windefend

  • One of the most commonly used commands to work with services is service restarting command. The structure of service restarting command is as such:

Restart-Service -Name Windefend

  • And lastly, the following command is used to temporarily suspend a service.

Suspend-Service -Name Windefend

These are the most commonly used command for service management in PowerShell. For more information about PowerShell commands and how they work, use the Get-Help command.