Starting/stopping SQL Server services
This recipe describes how to start and/or stop SQL Server services.
Getting ready
Check which SQL services are installed in your machine. Go to Start | Run and type Services.msc
. You should see a screen similar to this:
How to do it...
Let's look at the steps to toggle states for your SQL Server services:
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Add the following code. Note that this code will work in both PowerShell V2 and V3:
$Verbosepreference = "Continue" $services = @("SQLBrowser", "ReportServer") $hostName = "KERRIGAN" $services | ForEach-Object { $service = Get-Service -Name $_ if($service.Status -eq "Stopped") { Write-Verbose "Starting $($service.Name) ...." Start-Service -Name $service.Name } else { Write-Verbose "Stopping $($service.Name) ...." Stop-Service -Name $service.Name } } $VerbosePreference = "SilentlyContinue"
Execute and...