How to change a service startup type with PowerShell

By | September 5, 2012

Changing a service startup type can be crucial after installing or configuring the service.

PowerShell comes with an easy way to do so:

Set-Service –Name theservice –Computer thecomputer –StartupType “selectedType”

Where selectedType value can be:

  • Automatic
  • Manual
  • Disabled

Unfortunately, there is no support for the automatic (delayed start). To support the automatic (delayed start), you need to create a REG_DWORD value called DelayedAutoStart under HKLM\System\CurrentControlSet\Services\. A simple way to do so would be:

Set-ItemProperty -Path "Registry::HKLM\System\CurrentControlSet\Services\theservice" -Name "DelayedAutostart" -Value 1 -Type DWORD

 
10 Kudos
Don't
move!

10 thoughts on “How to change a service startup type with PowerShell

  1. xenon

    Alternatively you can do it like this:
    #$server is the server name you want to change
    #$service is the service name
    $command = “sc.exe \\$server config $service start= delayed-auto”
    $output = invoke-expression -command $command
    write-host $server ” ” $output

    Notes: space is important between start= delayed-auto. sc.exe is important otherwise it just doesn’t work using just sc.

    wrap that in a for loop and you can change a batch at once 🙂

    Reply
  2. Bill

    The another way:
    Using WMI:

    $Object = Get-WmiObject -class win32_service -Filter “name=’BITS'”
    $Object.ChangeStartMode(‘Disable’)

    Reply
  3. Bill Curtis

    Brilliant article, here is how I adapted it for my need. I needed to set the DelayedAutoStart on about 40 servers and the service name had spaces on it. (% is an alias that replaces ‘foreach’)

    To set Delayed AutoStart on any computer with a name that starts with bs- with a service named “Test Service Name”. I included the name in Quotes because the one I needed in my environment had spaces.

    get-adcomputer -filter ‘name -like “bs-*”‘ | select name | % { invoke-command -ComputerName $_.name -ScriptBlock { Set-ItemProperty -Path “registry::HKLM\System\CurrentControlSet\Services\” -name “DelayedAutoStart” -Value 1 -type DWORD | select pscomputername, delayedautostart } }

    To check the Services when it is done.
    get-adcomputer -filter ‘name -like “bs-*”‘ | select name | % { invoke-command -ComputerName $_.name -ScriptBlock { get-itemproperty “registry::HKLM\System\CurrentControlSet\Services\Test Service Name” -name “DelayedAutoStart” | select pscomputername, delayedautostart } }

    Reply
  4. Matt

    any tips to; write a command line that changes the startup type of the BITS service to Manual?

    Reply
  5. cheryl O M

    Powershell is great for many things, unfortunately when you want to modify the nuts and bolts of some key components like services you need to rely on ‘sc’ or cmd prompt. :/ Powershell gets you 80% of the way .. but when you really want to tweak the OS you need to know cmd unfortunately.

    Reply
  6. Suraj Singh

    I Tried to change Startup type to Automatic, but it is failing in powershell script.
    Set-Service -name Servicename -StartUpType “Automatic”.

    While I tried to change it Manual, it works.

    Any Help will be Appreciated.

    Thanks
    Suraj

    Reply
    1. Ali Momen

      Hello Suraj.
      I saw your comment just now and I do not suppose that my response would do you any good after 2 years, but here are two counter-actions you can take:
      1. Check if your powershell version supports the command
      2. Every service has a ‘Name’ and a ‘DisplayName’. You can get them using various commands including:
      Powershell:
      get-service
      cmd:
      sc queryex type=service state=all
      Make sure you enter ‘Name’ in your powershell command.

      Reply

Thoughts?