views:

294

answers:

1

Hello everyone,

If I know a service name, and have enough permission. My question is how to set a Windows Service to be auto-restart in PowerShell? I am using PowerShell 1.0, OS is Windows Server 2003.

thanks in advance, George

+3  A: 

Are you perchance asking for

Set-Service [service name] -startuptype automatic

EDIT

>get-help set-service

NAME
    Set-Service

SYNOPSIS
    Starts, stops, and suspends a service, and changes its properties.


SYNTAX
    Set-Service [-StartupType {Automatic | Manual | Disabled}] [-DisplayName <string>] [-PassThru] [-Status <string>] [
    -InputObject <ServiceController>] [-Description <string>] [-ComputerName <string[]>] [-confirm] [-whatif] [<CommonP
    arameters>]

    Set-Service [-Status <string>] [-StartupType {Automatic | Manual | Disabled}] [-Description <string>] [-Name] <stri
    ng> [-PassThru] [-DisplayName <string>] [-ComputerName <string[]>] [-confirm] [-whatif] [<CommonParameters>]
Steve Gilham
It's for setting service stratup mode. But I suppose, George want to configure service for auto-restart when it crashes.
Sergey Olontsev
Error information when executing your command => Set-Service : A parameter cannot be found that matches parameter name 'starttype'.
George2
HawX, I want to set it to be automatic start during system start-up.
George2
Sorry, I am wrong. I have a typo, should use startuptype other than starttype.
George2
I have a related question here, appreciate if you could help. :-)http://stackoverflow.com/questions/1218969/error-stopping-a-windows-service
George2