Quantcast
Viewing all articles
Browse latest Browse all 40

Showing and Killing SQL Server Processes with PowerShell

Another post in the PowerShell Box of Tricks series. There are much better ways of doing this I admit but as you can do it with PowerShell I created a function to do it.

Create a Server Object and notice that there is a Method named EnumProcesses by piping it to Get-Member and then look at the Properties and Methods of EnumProcesses

Image may be NSFW.
Clik here to view.
image

Once I had done that then it was easy to create a function to display what is going on. It’s quick and easy. Not as good as sp_WhoIsActive but it displays about the same info as sp_who, sp_who2

Image may be NSFW.
Clik here to view.
image

Image may be NSFW.
Clik here to view.
image

You can also find a Method called KillProcess on the Server Property so I asked a Yes/No question using Windows Forms. You can find much more detail on that here

Image may be NSFW.
Clik here to view.
image

All you need to supply is the spid

The code is here Show-SQLProcesses


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 40

Trending Articles