Export (0) Print
Expand All

Stop-Service

Updated: May 8, 2014

Applies To: Windows PowerShell 4.0

Stop-Service

Stops one or more running services.

Aliases

The following abbreviations are aliases for this cmdlet:

  • spsv

Syntax

Parameter Set: InputObject
Stop-Service [-InputObject] <ServiceController[]> [-Exclude <String[]> ] [-Force] [-Include <String[]> ] [-PassThru] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: Default
Stop-Service [-Name] <String[]> [-Exclude <String[]> ] [-Force] [-Include <String[]> ] [-PassThru] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: DisplayName
Stop-Service -DisplayName <String[]> [-Exclude <String[]> ] [-Force] [-Include <String[]> ] [-PassThru] [-Confirm] [-WhatIf] [ <CommonParameters>]




Detailed Description

The Stop-Service cmdlet sends a stop message to the Windows Service Controller for each of the specified services. You can specify the services by their service names or display names, or you can use the InputObject parameter to pass a service object representing the services that you want to stop.

Parameters

-DisplayName<String[]>

Specifies the display names of the services to be stopped. Wildcards are permitted.


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-Exclude<String[]>

Omits the specified services. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as "s*". Wildcards are permitted.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-Force

Allows the cmdlet to stop a service even if that service has dependent services.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Include<String[]>

Stops only the specified services. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as "s*". Wildcards are permitted.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-InputObject<ServiceController[]>

Specifies ServiceController objects representing the services to be stopped. Enter a variable that contains the objects, or type a command or expression that gets the objects.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByValue)

Accept Wildcard Characters?

false

-Name<String[]>

Specifies the service names of the services to be stopped. Wildcards are permitted.

The parameter name is optional. You can use "Name" or its alias, "ServiceName", or you can omit the parameter name.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByPropertyName, ByValue)

Accept Wildcard Characters?

true

-PassThru

Returns an object representing the service. By default, this cmdlet does not generate any output.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.ServiceProcess.ServiceController or System.String

    You can pipe a service object or a string that contains the name of a service to Stop-Service.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • None or System.ServiceProcess.ServiceController

    When you use the PassThru parameter, Stop-Service generates a System.ServiceProcess.ServiceController object representing the service. Otherwise, this cmdlet does not generate any output.


Notes

  • You can also refer to Stop-Service by its built-in alias, "spsv". For more information, see about_Aliases.

    Stop-Service can control services only when the current user has permission to do so. If a command does not work correctly, you might not have the required permissions.

    To find the service names and display names of the services on your system, type "get-service". The service names appear in the Name column and the display names appear in the DisplayName column.

Examples

-------------------------- EXAMPLE 1 --------------------------

This command stops the Performance Logs and Alerts (SysmonLog) service on the local computer.


PS C:\> stop-service sysmonlog

-------------------------- EXAMPLE 2 --------------------------

This command stops the Telnet service on the local computer. The command uses the Get-Service cmdlet to get an object representing the Telnet service. The pipeline operator (|) pipes the object to the Stop-Service cmdlet, which stops the service.


PS C:\> get-service -displayname telnet | stop-service

-------------------------- EXAMPLE 3 --------------------------

The Stop-Service command stops the IISAdmin service on the local computer. Because stopping this service also stops the services that depend on the IISAdmin service, it is best to precede the Stop-Service command with a command that lists the services that depend on the IISAdmin service.

The first command lists the services that depend on IISAdmin. It uses the Get-Service cmdlet to get an object representing the IISAdmin service. The pipeline operator (|) passes the result to the Format-List cmdlet. The command uses the Property parameter of Format-List to list only the Name and DependentServices properties of the service.

The second command stops the IISAdmin service. The Force parameter is required to stop a service that has dependent services. The command uses the Confirm parameter to request confirmation from the user before stopping each service.


PS C:\> get-service iisadmin | format-list -property name, dependentservices
PS C:\>stop-service iisadmin -force -confirm

Related topics



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft