Suspend-Service

Updated: August 9, 2015

Suspend-Service

Suspends (pauses) one or more running services.

Syntax

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

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

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




Detailed Description

The Suspend-Service cmdlet sends a suspend message to the Windows Service Controller for each of the specified services. While suspended, the service is still running, but its action is stopped until resumed, such as by usingthe Resume-Service cmdlet. You can specify the services by their service names or display names, or you can use the InputObject parameter to pass a service object that represents the services that you want to suspend.

Parameters

-DisplayName<String[]>

Specifies the display names of the services to be suspended. Wildcard characters are permitted.


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Exclude<String[]>

Specifies services to omit from the specified services. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as "s*". Wildcard characters are permitted.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Include<String[]>

Specifies services to suspend. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as "s*". Wildcard characters are permitted.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InputObject<ServiceController[]>

Specifies ServiceController objects that represent the services to suspend. 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 suspend. Wildcard characters are permitted.

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


Aliases

ServiceName

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true(ByValue,ByPropertyName)

Accept Wildcard Characters?

false

-PassThru

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.


Aliases

none

Required?

false

Position?

named

Default Value

none

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: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see    about_CommonParameters.

Inputs

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

  • System.ServiceProcess.ServiceController, System.String

    You can pipe a service object or a string that contains a service name to this cmdlet.


Outputs

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

  • None, System.ServiceProcess.ServiceController

    This cmdlet generates a System.ServiceProcess.ServiceController object that represents the service, if you specify the PassThru parameter. Otherwise, this cmdlet does not generate any output.


Notes

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

  • Suspend-Service can suspend only services that support being suspended and resumed. To determine whether a particular service can be suspended, use the Get-Service cmdlet together with the CanPauseAndContinue property. For example, Get-Service wmi | Format-List Name, CanPauseAndContinue. To find all services on the computer that can be suspended, type Get-Service | Where-Object {$_.CanPauseAndContinue -eq "True"}.

  • 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: Suspend a service

This command suspends the Telnet service (Tlntsvr) service on the local computer.


PS C:\> Suspend-Service -DisplayName "Telnet"

Example 2: Display what would happen if you suspend services

This command tells what would happen if you suspended the services that have a service name that starts with lanman. To suspend the services, rerun the command without the WhatIf parameter.


PS C:\> Suspend-Service -Name lanman* -WhatIf

Example 3: Get and suspend a service

This command uses the Get-Service cmdlet to get an object that represents the Task Scheduler (Schedule) service on the computer. The pipeline operator (|) passes the result to Suspend-Service, which suspends the service.


PS C:\> Get-Service schedule | Suspend-Service

Example 4: Suspend all services that can be suspended

This command suspends all of the services on the computer that can be suspended. It uses Get-Service to get objects that represent the services on the computer. The pipeline operator passes the results to the Where-Object cmdlet, which selects only the services that have a value of $True for the CanPauseAndContinue property. Another pipeline operator passes the results to Suspend-Service. The Confirm parameter prompts you for confirmation before suspending each of the services.


PS C:\> Get-Service | Where-Object {$_.CanPauseAndContinue -eq "True"} | Suspend-Service -Confirm

Related topics

Community Additions

ADD
Show: