Posted On September 1, 2020

PowerShell: Graceful Shutdown of MS SQL Server

kimconnect 0 comments
blog.KimConnect.com >> Database >> PowerShell: Graceful Shutdown of MS SQL Server
import-module sqlps
CD SQLSERVER:\SQL\$env:computername
$sql = (get-item .).ManagedComputer
# This command stops MSSQL$instanceName, SQLSERVERAGENT, SQLAGENT$instanceName, and SQLBROWSER
$sql.Services|%{$_.Stop()}

# Alternative method: less thorough
stop-service mssqlserver
# Sample output:
PS SQLSERVER:\SQL\SQL05> $sql.Services.Name
MSSQLFDLauncher
MSSQLSERVER
SQLBrowser
SQLSERVERAGENT

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Optimize SQL Server Memory & CPU Resources

# optimizeSqlServer.ps1 # Version 0.0.2 # This version deals with Memory, CPU # Future versions…

iSeries Access ODBC Setup

Run ODBC Data Source Administrator > click on System DSN

SQL: Use PowerShell to Validate if Database Exists

This function may be invoked remotely from a machine that has SQL-PS module installed. The…