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

SQL replace character in string

update g2_Item set g_title = replace(g_title, '_', ' '); update g2_Item set g_title = replace(g_title,…

SQL: Creating a Storage Report of Databases Residing within Server

Method 1: -- Get sizes of all databases from system (not real-time) WITH fs AS…

PowerShell: Backup, Archive, and Remove a Microsoft SQL Database

$sqlServer='sqlsherver007' $databaseName="someDatabaseName" $saCredential=get-credential $backupDestination="\\Archive03\MSSQL_Backups" function triggerSqlBackup($sqlServer,$databaseName){ # Ensure the the Jump Box has SQL PowerShell…