Remote Stop / Start - SQL Services

  • Hello,

    In joined new environmet, DBA's are responsible of SQL Server Services (e.g. MSSQLSERVER and SQLSERVERAGENT etc.). When there is restart of Windows box, DBA's need to stop SQL Server Services and disable them before windows reboot. Sometimes there will be more servers to deal with. I know the below command to stop and start the services remotely. Please let me know the script / command which disables the services remotely and start the services in automatic status.

    sc \\ServerName STOP "SQLSERVERAGENT"

    sc \\ServerName STOP "MSSQLSERVER"

    sc \\ServerName START "MSSQLSERVER"

    sc \\ServerName START "SQLSERVERAGENT"

    Thanks in advance.

  • You can use PowerShell to perform this much more efficiently to stop the service and disable it at the same time:

    Get-Service -ComputerName MyServer -name MSSQLSERVER | Stop-Service -PassThru | Set-Service -StartupType disabled

    Then the reverse:

    Get-Service -ComputerName MyServer -name MSSQLSERVER | Start-Service -PassThru | Set-Service -StartupType Automatic

    Additionally you should be able to pass in all the servers at once if you are working with the default instances across all of the servers:

    Get-Service -ComputerName MyServer, MyServer1, MyServer2, MyServer3 -name MSSQLSERVER | Stop-Service -PassThru | Set-Service -StartupType disabled

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

  • Thanks very much Shawn.

    Can same be achieved through sc?

    Thanks in advance.

  • According to documentation, yes but I don't know that it works remotely.

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

  • Thanks very much for your response Shawn.

  • the "sc" command does work remotely on 'other' servers - it is just a permissions issue.

    below is the first part of the command 'sc /?'

    DESCRIPTION:

    SC is a command line program used for communicating with the

    Service Control Manager and services.

    USAGE:

    sc <server> [command] [service name] <option1> <option2>...

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply