How to stop service with their dependent services in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To stop the service which has dependent service in PowerShell -Force parameter is used. First, we will check what are the dependent services for specific service, to get them -DependentService parameter is used.

Example

For example, WMI service (Name: Winmgmt) has multiple dependent services.

Get-Service -Name Winmgmt -DependentServices

Output

tatus   Name           DisplayName
------   ----           -----------
Running  UALSVC           User Access Logging Service
Stopped  smstsmgr           ConfigMgr Task Sequence Agent
Stopped  SepLpsService      Symantec Endpoint Protection Local ...
Stopped  NcaSvc           Network Connectivity Assistant
Running  iphlpsvc           IP Helper
Running  CcmExec           SMS Agent Host

Now, we will stop Winmgmt Service along with their dependent services with -Force parameter. To check the command process -verbose parameter is added.

Stop-Service -Name Winmgmt -Force -Verbose

With Displayname,

Stop-Service -DisplayName "Windows Management Instrument" -Force -Verbose

Another way to stop the dependent service is to get the dependent services first and then pipeline Stop-Service parameter and you don’t need to use -Force parameter this time, but this will only stop the dependent services, not the service which is specified.

Get-Service Winmgmt -DependentServices | Stop-Service -Verbose

The above command will stop the dependent services of Winmgmt but not itself.

raja
Published on 22-Jan-2020 10:26:00
Advertisements