EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Stop Service
Secondary Sidebar
PowerShell Tutorial
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

PowerShell Stop Service

PowerShell Stop Service

Introduction to PowerShell Stop Service

Stop-Service cmdlet in PowerShell is used to stop the running service on the local computer or remote computers. You can stop one or multiple services together. For example, service can be stopped by Name, Display Name, or the Input Object.

Syntax: 

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

The Stop-Service command uses the below syntaxes.

Stop-Service
[-Force] [-NoWait] [-Name] <String[]>
[-InputObject] <ServiceController[]>
[-DisplayName] <String[]>
[-PassThru] [-Include <String[]>] [-Exclude <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Parameters

Here are the following parameters of PowerShell Stop-Service

1. -Name

This parameter is used for the service name or the alias name. You can use the wildcard character (*). To stop the multiple services, you can separate them by comma (,). For example, the Print Spooler service has the alias name Spooler, like all other services have their own alias names.

2. –DisplayName

When you use this parameter, you need to provide the display name of the service. It is a string datatype. You can provide multiple display names separated by comma (,). Wildcard character (*) is permitted.  For example, “Windows Management Instrument” is the display name of the winmgmt service alias.

3. –InputObject

You can provide multiple services as a variable to the input object parameter to stop the services on the local and remote computers.

4. –Include

This parameter specifies the service name to include when you stop any service. The value of this parameter qualifies the Name parameter. You can use the wildcard character (*). For example, When you specify S*, it will stop all the services starting with S.

5. –Exclude

This parameter specifies the service name to exclude when you stop any service. The value of this parameter qualifies the Name parameter. You can use the wildcard character (*). For example, when you specify S*, it will stop the remaining services, excluding the services starting with S.

6. –Passthru

By default, Stop-Service doesn’t display the output in the PowerShell console. When you use this parameter, the output will be displayed in the PowerShell console.

7. –WhatIf

When this parameter is used, it shows the operation going to perform when the Stop-Service will run, without running the actual command.

8. –Confirm

This parameter will prompt for user consent before stopping the service(s). Below options are available with the –Confirm parameter.

[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is “Y”):

Y (Yes) – It will stop the single service, and if there are multiple services, the check will run again for the next service.

A (Yes to All) – It will stop all the services provided in the Stop-Service command.

N (No): It will not stop the single service, and if there are multiple services, the check will run again for the next service.

L (No to All): It will not stop all the services provided in the Stop-Service command.

S (Suspend): It will skip the service from stopping, which means it will leave the service in the current state.

9. –Force

Using the Force parameter will stop the services even if the service has the dependent services running. So it first stops the dependent services and, latter, the service itself.

10. –NoWait

When you specify the –Nowaitparameter, the PowerShell console doesn’t wait for the service to stop, and execution moves to the next code.

11. –CommonParameters

Below common parameters are supported by the Stop-Service.

-Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningVariable, -WarningAction, -OutBuffer, -OutVariable.

Examples of PowerShell Stop Service

Different examples are mentioned below:

1. Stop-Service cmdlet

When you just write the Stop-Service, it will wait for the input object, as shown below. Input Object can be Service alias name, Display Name, or the InputObject like a variable.

Stop-Service

Output:

PowerShell Stop-Service output 1

2. Stop-Service with the –Name Parameter

You can provide the Service name (alias name) after the –Name parameter. Stop-Service cmdlet takes the –Name as the default parameter. You will not get any output in the console when you stop the service. You need to use the Get-Service command to retrieve the status of the service. You can also use –PassThru parameter that is explained later in subsequent examples.

Stop-Service -Name Spooler
Get-Service Spooler

Output:

PowerShell Stop-Service output 2

You can stop multiple services by separating them with a comma (,). For example,

Stop-Service -Name Spooler, Winmgmt, PlugPlay
Get-Service Spooler, Winmgmt, PlugPlay

Output:

PowerShell Stop-Service output 3

You can also use the wildcard character (*) as well.

For example,

Stop-Service -Name Spooler, "Winmg*", "*Plug*" -PassThru

Output:

PowerShell Stop-Service output 4

3. Stop-Service with the –Passthru parameter

In the above example, we have seen that we need to use the Get-Service cmdlet to get the service status. You can also use –Passthru parameter, which displays the output in the console itself.

Stop-Service -Name Spooler, Winmgmt, PlugPlay -PassThru

Output:

PowerShell Stop-Service output 5

4. Stop-Service with the –DisplayName parameter

You can provide the display names as an input to the Stop-Service to stop the services.

For example,

Stop-Service -DisplayName "Plug*","Print Spooler" -PassThru

Output:

PowerShell Stop-Service output 6

5. Stop-Service with the –InputObject Parameter

Here, we will store a few service alias names in the variable and pass it to the InputObject parameter.

$services = "Spooler","Plugplay","Winmgmt"
Stop-Service -InputObject $services -PassThru

Output:

PowerShell Stop-Service output 7

6. Stop-Service with the –Include Parameter

In the given variable below, we will need to stop only the “Print Spooler” service. So when we use –Include parameter, it will include Spooler service only.

$services = "Spooler","Plugplay","Winmgmt"
Stop-Service $services -Include "Spoo*" -PassThru

Output:

output 8

7. Stop-Service with –Exclude Parameter

The variable given below will exclude the Spooler service, so the other two services will be restarted automatically.

$services = "Spooler","Plugplay","Winmgmt"
Stop-Service $services -Exclude "Spoo*" -PassThru

Output:

output 9

8. Stop-Service with –WhatIf parameter

Whatif parameter will predict the command execution without actually executing the command. An example is shown below.

Stop-Service -Name Spooler -WhatIf

Output:

output 10

9. Stop-Service with –Confirm Parameter

You can use the –Confirm parameter with the Boolean values ($true or $false). When you specify $true, service will not be stopped, but it will prompt for user consent, and with the $false, service will be stopped.

Stop-Service -Name Spooler -Confirm:$false -PassThru

Output: 

output 11

Stop-Service -Name Spooler -Confirm:$true -PassThru

Output: 

output 12

 10. Stop-Service with –Force Parameter

Few services have dependent services and can’t be stopped directly without stopping the dependent services. So –Force parameter stops the service and its dependent services. For example, Winmgmt service.

Stop-Service Winmgmt -Force -PassThru

Output: 

output 13

11. Stop-Service with –NoWait parameter

Some services take time to stop, and execution halts until then. For example, the –NoWait parameter stops in the background, and execution moves to the next code.

For example,

Stop-Service Winmgmt -NoWait -PassThru

Output: 

output 14

Recommended Articles

This is a guide to PowerShell Stop Service. Here we discuss the Examples of PowerShell Stop Service along with the syntax and parameters. You may also have a look at the following articles to learn more –

  1. PowerShell Get-Item
  2. PowerShell Split String
  3. PowerShell Get-Process
  4. String in PowerShell
Popular Course in this category
PowerShell Training (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |   4+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
Data Visualization Training (15 Courses, 5+ Projects)4.7
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more