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 *