≡ Menu

Change startup mode of a windows service using powershell

The Powershell script discussed in this post will help you to change Startup type (Automatic Manual, Disabled) of a windows service on local or remote computer.

In my previous post we have seen how to query startup type of a windows service using powershell. In post article we will further discuss on the same topic and figure out how to change or update the startup type of a windows service to Automatic or Manual or Disabled. In my previous post, I switched to WMI method as the built-in Service related powershell cmdlets doesn’t support querying the startup type. However, they have the ability to change the startup type of the service to either of Automatic, Manual, Disabled.

Here is the script(Set-ServiceStartupType.ps1) that sets the startup type of multiple services on local or remote computer.

[cmdletbinding()]            

param(            
[string[]]$Service,            
[Validateset("Automatic","Manual","Disabled")]            
[string]$Type,            
[string]$ComputerName            
)            

foreach($Ser in $Service) {            
 try {            
  $ServiceObj = Get-Service -Name $Ser -ComputerName $ComputerName -ErrorAction Stop            
  Set-Service -InputObj $ServiceObj -StartupType $Type -ErrorAction Stop            
  Write-Host "Successfully changed the start up type of $Ser to $type mode on $ComputerName"            
 } catch {            
  Write-Error " Failed to get the information. More details: $_"            
 }            
}

Usage examples:

  • .\Set-ServiceStartupType.ps1 -Service gupdate -ComputerName mypc1 -Type Disabled — sets the startup type of gupdate service to Disabled on computer called mypc1
  • .\Set-ServiceStartupType.ps1 -Service gupdate,wsearch -Type Disabled — sets the startup type of gupdate and wsearch services to disabled on local computer.