Techibee.com

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:

 

 

Exit mobile version