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

5 Kudos

6 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 🙂

  2. Bill

    The another way:
    Using WMI:

    $Object = Get-WmiObject -class win32_service -Filter “name=’BITS'”

  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 $ -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 $ -ScriptBlock { get-itemproperty “registry::HKLM\System\CurrentControlSet\Services\Test Service Name” -name “DelayedAutoStart” | select pscomputername, delayedautostart } }