July 14, 2014 at 11:33 am
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.
July 14, 2014 at 12:12 pm
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
July 14, 2014 at 12:25 pm
Thanks very much Shawn.
Can same be achieved through sc?
Thanks in advance.
July 14, 2014 at 12:29 pm
According to documentation, yes but I don't know that it works remotely.
Shawn Melton
Twitter: @wsmelton
Blog: wsmelton.github.com
Github: wsmelton
July 14, 2014 at 12:42 pm
Thanks very much for your response Shawn.
July 15, 2014 at 12:28 pm
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