Start-Service

 

Additional Resources for Start-Service

 

Starting a Stopped Service

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

 

 

SYNOPSIS

Starts one or more stopped services.

 

SYNTAX

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

 

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

 

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

 

DETAILED DESCRIPTION

The Start-Service cmdlet sends a start message to the Windows Service Controller for each of the specified services. If a service is already running, the message is ignored without error. You can specify the services by their service names or display names, or you can use the InputObject parameter to supply a service object representing the services that you want to start.

 

PARAMETERS

 

-name <string[]>

Specifies the service names for the service to be started.

 

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

 

Required?

true

Position?

1

Default value

 

Accept pipeline input?  

true (ByValue, ByPropertyName)

Accept wildcard characters? 

true

 

-include <string[]>

Starts 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 the services to be started. Wildcards are permitted.

 

Required?

true

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

true

 

-inputObject <ServiceController[]>

Starts 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

 

-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 Start-Service -detailed". For technical information, type "Get-Help Start-Service -full".

 

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

 

You can also refer to Start-Service by its built-in alias, "sasv". For more information, see About_Alias.

 

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

 

You can only start services that have a start type of "Manual" or "Automatic;" you cannot start services with a start type of "Disabled." If a Start-Service command fails with the message "Cannot start service <service-name> on computer," use a Get-WmiObject command to find the start type of the service and, if necessary, use a Set-Service command to change the start type of the service.

 

Some services, such as Performance Logs and Alerts (sysmonlog) stop automatically if they have no work to do. When Windows PowerShell starts a service that stops itself almost immediately, it displays the following message: "Service <display-name> start failed."

 

EXAMPLE 1

 

start-service -name eventlog

 

This command starts EventLog service on the local computer. It uses the Name parameter to identify the service by its service name.

 

EXAMPLE 2

 

start-service -displayname *remote* -whatif

 

This command tells what would happen if you started the services with a display name that includes "remote." It uses the DisplayName parameter to specify the services by their display name, instead of their service name, and the -whatif parameter to tell what would happen if the command were executed, instead of executing the command.

 

EXAMPLE 3

 

$s = get-service wmi

 

start-service -InputObject $s -passthru | format-list >> services.txt

 

These commands start the WMI service on the computer and add a record of the action to the services.txt file. The first command uses the Get-Servicecmdlet to get an object representing the WMI service and store it in the $s variable.

 

The second command uses the Start-Service cmdlet to start the WMI service. It identifies the service by using the InputObject parameter to pass the $s variable containing the WMI service object to Start-Service. Then, it uses the Passthru parameter to create an object that represents the starting of the service. Without this parameter, Start-Service does not create any output.

 

The pipeline operator (|) passes the object that Start-Service creates to the Format-Listcmdlet, which format the object as a list of its properties. The append redirection operator (>>) redirects the output to the services.txt file, where it added to the end of the existing file.

 

EXAMPLE 4

 

This series of commands shows how to start a service when the start type of the service is "Disabled." The first command, which uses the Start-Service cmdlet to start the Telnet service (tlntsvr), fails.

 

start-service tlntsvr

 

Start-Service : Service 'Telnet (TlntSvr)' cannot be started due to the followng error: Cannot start service TlntSvr on computer '.'.

At line:1 char:14

+ start-service  <<<< tlntsvr

 

The second command uses the Get-WmiObjectcmdlet to get the Tlntsvr service. This command retrieves an object with the start type property in the "StartMode" field. The resulting display reveals that the start type of the Tlntsvr service is "Disabled."

 

 get-wmiobject win32_service | where {$_.Name -eq "tlntsvr"}

 

ExitCode  : 0

Name  : TlntSvr

ProcessId : 0

StartMode : Disabled

State : Stopped

Status: OK

 

The next command uses the Set-Servicecmdlet to change the start type of the Tlntsvr service to "Manual."

 

 set-service tlntsvr -startuptype manual

 

Now, we can resubmit the Start-Service command. This time, the command succeeds.

 

 start-service tlntsvr

 

To verify that the command succeeded use Get-Service.

 

RELATED LINKS

Get-Service

Suspend-Service

Stop-Service

Restart-Service

Resume-Service

Set-Service

New-Service