How to Set Service to Automatic Using PowerShell?

As a system administrator, you might need to manage services efficiently on Windows servers many times. One such thing is to start services automatically. In this tutorial, I will explain how to set a service to start automatically using PowerShell.

Setting services to start automatically ensures that critical services are always running when your system boots up. This is particularly important for services that are essential for the operation of applications or system processes.

Note: You need to have administrative privileges on the system where you want to set the service automatic.

Set Service to Automatic Using PowerShell using the Set-Service Cmdlet

The Set-Service cmdlet in PowerShell allows you to change the properties of a service on a local or remote computer. You can use it to start, stop, pause, or change the startup type of a service.

Syntax

The basic syntax for setting a service to automatic is:

Set-Service -Name "ServiceName" -StartupType Automatic

Now, let me show you some examples of Set-Service cmdlet in PowerShell.

Check out Change Windows 11 Desktop Background Color with PowerShell

Example 1: Setting the Windows Update Service to Automatic

Imagine you are managing a fleet of servers, and you want to ensure that the Windows Update service (wuauserv) is set to start automatically. Here’s how you can do it:

Set-Service -Name "wuauserv" -StartupType Automatic

This command will configure the Windows Update service to start automatically when the system boots up.

Example 2: Setting the Background Intelligent Transfer Service (BITS) to Automatic

The Background Intelligent Transfer Service (BITS) is used for asynchronous file transfers between machines. To set this service to start automatically, use the following command:

Set-Service -Name "BITS" -StartupType Automatic

After running this command, the BITS service will be configured to start automatically.

Example 3: Automating Multiple Services

If you need to set multiple services to start automatically, you can use a script to streamline the process. Here’s an example script that sets the BITS and Windows Update services to start automatically:

$services = @("BITS", "wuauserv")

foreach ($service in $services) {
    Set-Service -Name $service -StartupType Automatic
}

This script loops through each service in the $services array and sets its startup type to automatic.

PowerShell also allows you to manage services on remote computers. This can be particularly useful in a large enterprise environment. Let me show you some examples related to it.

Read Rename a Windows Computer Using PowerShell

Example 4: Setting a Service to Automatic on a Remote Computer

To set a service to automatic on a remote computer, use the Invoke-Command cmdlet. Here’s an example:

Invoke-Command -ComputerName "RemoteServer01" -ScriptBlock {
    Set-Service -Name "wuauserv" -StartupType Automatic
}

Replace "RemoteServer01" with the name of your remote server. This command will execute the Set-Service cmdlet on the specified remote server.

After setting the services to automatic, it’s important to verify that the changes have been applied correctly. You can use the Get-Service cmdlet to check the status and startup type of the services.

Example 5: Verifying Service Startup Type

To verify the startup type of the wuauserv service, use the following command:

Get-Service -Name "wuauserv" | Select-Object -Property Name, StartType

This command retrieves the Name and StartType properties of the wuauserv service, allowing you to confirm that it is set to start automatically.

Check out How to Change Wallpaper with PowerShell?

Troubleshooting Common Issues

Now, let me share some common issues that you may face while working with Set-Service cmdlet.

Issue 1: Insufficient Privileges

If you encounter an error stating that you do not have sufficient privileges, ensure that you are running PowerShell as an administrator. Right-click the PowerShell icon and select “Run as administrator.”

Issue 2: Service Name Errors

Ensure that the service name you are using is correct. You can get a list of all services and their names using the Get-Service cmdlet:

Get-Service

Issue 3: Remote Execution Failures

If you face issues executing commands on remote computers, ensure that PowerShell Remoting is enabled on the remote machine. You can enable it using the Enable-PSRemoting cmdlet:

Enable-PSRemoting -Force

Read Disable Local User Computer Accounts Using PowerShell

Set Services to Delayed Start in PowerShell

In some cases, you might want to set a service to start automatically but with a delay. This can help manage the startup load on the system. Here’s how to set a service to delayed start using PowerShell.

Set-Service -Name "wuauserv" -StartupType AutomaticDelayedStart

This command configures the wuauserv service to start automatically with a delay.

Example 6: Using New-Service to Create and Configure a New Service

If you need to create a new service and set it to start automatically, you can use the New-Service cmdlet. Here’s an example:

New-Service -Name "MyNewService" -BinaryPathName "C:\Path\To\Executable.exe" -StartupType Automatic -DisplayName "My New Service"

This command creates a new service named MyNewService, sets its executable path, and configures it to start automatically.

Set Service to Automatic Using PowerShell

Conclusion

In this tutorial, I explained how to set service to automatic using PowerShell with the Set-Service cmdlet with a few real examples. It will be easy to manage service startup types using PowerShell.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.