Cmdlets

Choose a cmdlet from the list on the left or search for a specific cmdlet. Choose a cmdlet from the list or search for a specific cmdlet.
About Help  Providers
 

Restart-Service

Restart-Service

microsoft.powershell.commands.management.dll

Synopsis

Stops and then starts one or more services.

Syntax

Restart-Service [-InputObject] [-Exclude] [-Force] [-Include] [-PassThru] [<CommonParameters>]

Restart-Service [-Exclude] [-Force] [-Include] [-PassThru] [-DisplayName] [<CommonParameters>]

Restart-Service [-Name] [-Exclude] [-Force] [-Include] [-PassThru] [<CommonParameters>]

Detailed Description

The Restart-Service cmdlet sends a stop message and then a start message to the Windows Service Controller for a specified service. If a service was already stopped, it is started without notifying you of an error. You can specify the services by their service names or display names, or you can use the InputObject parameter to pass an object that represents each service that you want to restart.

Parameters

-DisplayName <String[]>

Specifies the display names of services to be restarted. 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 <SwitchParameter>

Restarts a service that has dependent services.

Aliases

None

Required?

false

Position

named

Default value

False

Accept pipeline input?

false

Accept wildcard characters?

false

-Include <String[]>

Restarts 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 that represent the services to be restarted. 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 restarted.

Aliases

None

Required?

true

Position

1

Default value

None

Accept pipeline input?

true (ByPropertyName, ByValue)

Accept wildcard characters?

false

-PassThru <SwitchParameter>

Returns an object that represents 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

Input Type

System.ServiceProcess.ServiceController, System.String

Return Type

None or System.ServiceProcess.ServiceController

Notes

Restart-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 appears in the Name column, and the display names appear in the DisplayName column.

Examples

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

This command restarts the Windows Management Instrumentation service (WinMgmt) on the local computer.

PS C:\>Restart-Service winmgmt

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

This command restarts the services that have a display name that begins with "Net", except for the "Net Logon" service.

PS C:\>Restart-Service -DisplayName net* -Exclude "net logon"

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

This command starts all of the stopped network services on the computer.

It uses the Get-Service cmdlet to get objects representing the services whose service name begins with "net". (The optional Name parameter name is omitted.) The pipeline operator (|) sends the services object to the Where-Object cmdlet, which selects only the services with a status of "stopped." Another pipeline operator sends the selected services to Restart-Service. In practice, you would use the WhatIf parameter to see the effect of the command before using it.

PS C:\>Get-Service net* | Where-Object {$_.Status -eq "Stopped"} | Restart-Service

Online Version
Get-Service
New-Service
Resume-Service
Set-Service
Start-Service
Stop-Service
Suspend-Service