Restart-Service

 

Additional Resources for Restart-Service

 

Stopping and Restarting a Service

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/restart-service.mspx

 

 

SYNOPSIS

Stops and then starts one or more services.

 

SYNTAX

Restart-Service [-name] <string[]> [-force] [-include <string[]>] [-exclude <string[]>] [-passthru] [-whatIf] [-confirm] [<CommonParameters>]

 

Restart-Service -displayName <string[]> [-force] [-include <string[]>] [-exclude <string[]>] [-passthru] [-whatIf] [-confirm] [<CommonParameters>]

 

Restart-Service [-inputObject <ServiceController[]>] [-force] [-include <string[]>] [-exclude <string[]>] [-passthru] [-whatIf] [-confirm] [<CommonParameters>]

 

DETAILED DESCRIPTION

For each service that you restart, the Restart-Service cmdlet sends a stop message and then a start message to the Windows Service Controller. 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

 

-name <string[]>

Specifies the service names of services to be restarted.

 

Required?

true

Position?

1

Default value

 

Accept pipeline input?  

true (ByValue, ByPropertyName)

Accept wildcard characters? 

true

 

-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.

 

Required?

false

Position?

named

Default value

 

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.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

true

 

-passthru <SwitchParameter>

Passes the object created by this cmdlet through the pipeline. By default, this cmdlet does not pass any objects through the pipeline.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-displayName <string[]>

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

 

Required?

true

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

true

 

-inputObject <ServiceController[]>

Restarts the services represented by the specified ServiceController objects. Enter a variable that contains the objects or type a command or expression that gets the objects.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

true (ByValue)

Accept wildcard characters? 

false

 

-force <SwitchParameter>

Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will stop and restart a service that has dependent services.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-whatIf

Describes what would happen if you executed the command without actually executing the command.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

 false

 

-confirm

Prompts you for confirmation before executing the command.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

Object

 

NOTES

 

For more information, type "Get-Help Restart-Service -detailed". For technical information, type "Get-Help Restart-Service -full".

 

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 appears in the "DisplayName" column.

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

EXAMPLE 1

 

restart-service wmi

 

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

 

EXAMPLE 2

 

restart-service -displayname net* -exclude "net logon"

 

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

 

EXAMPLE 3

 

get-service net* | where {$_.Status -eq "Stopped"} | restart-service

 

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

 

It uses the Get-Servicecmdlet 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-Objectparameter, 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.

 

RELATED LINKS

Start-Service

Stop-Service

Suspend-Service

Resume-Service

New-Service

Get-Service

Set-Service