Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

Monday, January 19, 2009

contain the character sequence

to find running services that contain the character sequence 'sql' in the service's name

PS R:\> get-service "*sql*"
| where-object { $_.status -eq "running" }

or,

PS R:\> get-service
| where-object { $_.status -eq "running" }
| where-object { $_.name -match ".*sql.*" }


Status Name DisplayName
------ ---- -----------
Running MSSQLServer MSSQLServer

'start', 'stop' mssqlserver

[] to start a service by calling the ServiceController.Start method

PS R:\> (Get-Service mssqlserver).Start()

MSDE7 icon at system tray turned from 'Red' to 'Green'

[] to stop a service by calling the ServiceController.Stop method

PS R:\> (Get-Service mssqlserver).Stop()

MSDE7 icon at system tray turned from 'Green' to 'Red'

stop the MSDE7 SQL server NT service

PS> stop-service -name mssqlserver -force

WARNING: Waiting for service 'MSSQLServer (MSSQLServer)' to finish stopping...

'-force' must be applied here because it has dependencies.

Others are Logical Disk Manager, COM+ Event System, Workstation, Network Connections, SSDP Discovery Service, Windows Management Instrumentation.

terminate sessions of SQL

to terminate sessions of SQL Server with confirming

PS> get-process -name sql* | stop-process -passthru

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
52 2 900 3020 47 0.05 1564 sqlmangr

Warning!
Are you sure you want to perform this action?
Performing operation 'Stop-Process' on Target 'sqlservr(1072)'
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
(default is "Y"):l <--- stands for 'No to All'