How to use the command 'Start-Service' (with examples)

How to use the command 'Start-Service' (with examples)

The ‘Start-Service’ command in PowerShell is used to start one or more stopped services. It is a powerful command that helps system administrators manage services on a Windows machine. This article will illustrate some use cases of the ‘Start-Service’ command.

Use case 1: Start a service by using its name

Code:

Start-Service -Name service_name

Motivation: The motivation behind using this example is to quickly start a specific service by providing its name as an argument to the command. This is useful when you know the name of the service you want to start.

Explanation:

  • ‘-Name’ is a parameter of the ‘Start-Service’ command that specifies the name of the service you want to start. You need to replace ‘service_name’ with the actual name of the service you want to start.

Example output: If the service with the name ‘Print Spooler’ is stopped, running the following command would start it:

Start-Service -Name "Print Spooler"

Use case 2: Display information without starting a service

Code:

Start-Service -DisplayName *name* -WhatIf

Motivation: The motivation behind using this example is to preview the action of starting a service without actually starting it. This can provide information about the service without affecting its current state.

Explanation:

  • ‘-DisplayName’ is a parameter of the ‘Start-Service’ command that specifies the display name of the service you want to preview. You need to replace ‘name’ with the part or complete display name of the service.
  • ‘-WhatIf’ is a common parameter of PowerShell that allows you to see what would happen if the command runs without actually running it.

Example output: Running the following command would preview the action of starting a service with a display name containing the word ‘Print’:

Start-Service -DisplayName *Print* -WhatIf

Use case 3: Start a disabled service

Code:

Set-Service service_name -StartupType manual; Start-Service service_name

Motivation: The motivation behind using this example is to start a service that is currently disabled. This involves first setting the ‘StartupType’ of the service to ‘Manual’ and then starting the service.

Explanation:

  • ‘-StartupType’ is a property of a service that determines how the service starts or is triggered. By specifying ‘manual’, you set the StartupType to ‘Manual’, which means the service will have to be started manually.
  • The ‘Set-Service’ command is used to modify the properties of a service. In this case, we are using it to set the StartupType of a service to ‘Manual’.
  • The semicolon ‘;’ is used to separate multiple commands on a single line in PowerShell.

Example output: If the service with the name ‘Print Spooler’ is currently disabled, running the following command would start it by setting the StartupType to ‘Manual’ and then starting the service:

Set-Service "Print Spooler" -StartupType Manual; Start-Service "Print Spooler"

After running this command, the ‘Print Spooler’ service would start and its StartupType would be set to ‘Manual’.

Conclusion:

The ‘Start-Service’ command in PowerShell is a versatile tool for starting services on a Windows machine. It allows you to start a service by its name, preview the action of starting a service without actually starting it, and start a disabled service by modifying its StartupType. By understanding these use cases, you can effectively manage services using PowerShell.

Related Posts

How to use the command powerstat (with examples)

How to use the command powerstat (with examples)

Powerstat is a command-line tool that allows users to measure the power consumption of a computer that has a battery power source or supports the RAPL interface.

Read More
How to use the command Get-WUApiVersion (with examples)

How to use the command Get-WUApiVersion (with examples)

This command is part of the external PSWindowsUpdate module and is used to get the version of the Windows Update Agent.

Read More
How to use the command "poweroff" (with examples)

How to use the command "poweroff" (with examples)

The poweroff command is used to shut down the system. It is a simple and convenient way to power off the computer without having to use any additional tools or methods.

Read More