How to start SQL Server instance if stopped using PowerShell?
If you do not have a monitoring system for your services like SQL server service, you can run an automatic job or task to Handel this process….
First: create a PowerShell script….
$servername = "Put server
name" #Put your server name or IP
$serviceName = "MSSQLSERVER" #SQL Server
Service name
$service = Get-Service -ComputerName $servername
-Name $serviceName #Get
Service as object
if ($service.Status
-ne "Running") #Check if the
service is not Running
{
start-Service $service #Start the service
# Also you can send a notification email
}
|
Second: Run PowerShell script using windows scheduled tasks or by any automatic service…
Create the scheduled task and set
the action to:
Program/Script: Powershell.exe
Arguments: -File "C:\Users\MyUser\Documents\ThisisMyFile.ps1"
Add a schedule to run script on
time interval.