Powershell : Killing all processes of name

Now I am just starting with PowerShell, so I will likely come up with some ridiculously simple examples.

One of thing I really like about PowerShell is the ability to pipe things from one CmdLet  to another.

Imagine you want to get all instances of the the running process “notepad” and kill them.

This is easily achieved using the following code

GetProcess "notepad" | StopProcess


Like  I say this is ridiculously simple, and hardy worthy of a blog post at all, but I aim to build a set of common tasks posts, and this will just form one of those.

So until next time


10 thoughts on “Powershell : Killing all processes of name

  1. Thanks! I’ve idly wanted a unix-style killall command a handful of times over the years.

  2. Andre says:

    I have been wondering about Powershell as well for sometime, but have not yet found use for it, as I’m a developer and not an administrator. However, I have noted this in the back of my mind, in case I ever get in a situation where one has a lot processes running or a self spawning process that won’t go away.

    • sachabarber says:

      I am a dev too, thing is we use continuous integration/deployment, which means lots of scripts. Right now we use BAT files and NANT files. But PowerShell is way more powerful hands down. Its “wicked awesome dude”, as my son would say

    • Dan says:

      Ever buy a tool for some specific job around the house, and a year later find you used that tool in ways you didn’t imagine when you bought it? That’s how PowerShell is.

      I’m a dev too, and ramping up on PowerShell. Have used cmd/batch files for decades.

      I’m finding that PowerShell commandlets for various development tasks are much better in versatility and expressiveness than DOS based commands. For some development work, like SharePoint development, PowerShell is extremely useful.

    • wekempf2013 says:

      I’m a Dev, and use PowerShell for Dev purposes all the time. Even simple things are super useful.

      PS> gci -inc bin,obj -rec | rm -rec -force

      That wipes out all of the “bin” and “obj” directories in the current directory and every subdirectory. Super useful to run in your workspace directory to get to a “clean” state, especially when someone messes up and there’s something that a Clean or Rebuild inside the IDE doesn’t catch.

      I’ve written PowerShell scripts to find resource names in Resx files that aren’t referenced in code anywhere, something super useful to do before sending your Resx out to be translated by some company that charges you by the word.

      I’ve written PowerShell scripts to automate certain repetitive tasks, like creating new branches in source control.

      “I’m a developer and not an admistrator” is no reason to not learn and use PowerShell. 😉

      • sachabarber says:

        Thanks for that Bill. We use a shed load of NANT to automate things right now, but I am really digging powershell a lot too. Think I’m going to post your up (full credits obviously).

      • Andre says:

        I guess my environment causes me not to learn it then, being a Visual Studio with SourceSafe , these things are already cared for. We also have a tight development environment with only two developers and a systems architect. Don’t get me wrong, I understand it is powerful, but still couldn’t see any advantages specifically for us that isn’t covered in our tools. As have investigated it though, looking at examples and tutorials around the web – haven’t seen anything I would use to resolve an issue I can handle in another manner. The reason I was refferring to administrators is because most of the examples I saw was for administrative tasks.

  3. wekempf2013 says:

    I prefer MSBuild over NANT, but both of those are for automating builds. The things I use PowerShell for have little or nothing to do with builds. They’re generally one-off or infrequent things that you do that would be repetitive, time consuming and even sheer drudgery to do by hand, but take you a second or two to type a command into PowerShell or a minute or two to create a script for. I use PowerShell nearly every day, and my favorite extension in Visual Studio is the “Package Manager” installed by NuGet (so, now a part of the IDE proper, I guess) which puts PowerShell inside the IDE. I don’t use it much, but one of the coolest things I’ve ever worked with is StudioShell (http://studioshell.codeplex.com/) which allows you to automate things inside of Visual Studio using PowerShell.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: