A PowerShell command you should avoid

While I was writing my presentation on PowerShell, I did one spectacularly dumb thing which I thought might be fun to share.

I was doing some screen-captures for use in slides, to show how you can stop a process.

What I meant to type was:

Get-Process notepad | Stop-Process

Get me all of the notepad processes, and pipe them to Stop-Process which will stop them.

But stuck deep in PowerPoint slide-producing-hell, my fingers ran quicker than my brain and what I actually typed was:

Get-Process | Stop-Process

Crap.

Fancy taking a guess what that did?

Get-Process (without any arguments) gets all the running processes.

So…

Get me all of the processes, and pipe them to Stop-Process. All of them. Not just apps. Not even just explorer – the shell-level stuff. Everything.

Windows doesn’t like it when you kill it’s kernel processes. 🙁

blue screen of death

… Type, Screenshot, Copy, Paste, New slide, Type, BLUE SCREEN OF DEATH.

Woops.

4 Responses to “A PowerShell command you should avoid”

  1. Andy Piper says:

    That’s spectacularly silly though – I guess a relatively easy mistake to make. Shame that PowerShell doesn’t protect you in anyway from that one.

  2. dale says:

    It can protect you… if you plan ahead that you need protecting

    If I’d done Get-Process | Stop-Process -WhatIf it would have shown me what processes it would have stopped.

    Or if I’d done Get-Process | Stop-Process -Confirm it would have asked “Are you sure?” before each one.

    That kinda relies on you to know you’re about to do something stupid, though 🙂

    I guess I’ve found something to add to the list of commands that I shouldn’t be allowed near. Right after rm -rf *

  3. I can relate to the dangers of the “rm -rf *” command…

    When I was at University I was working on an assignment late one night, and had just completed it. Getting ready to submit I decided to clean up my text editor’s backup files via “rm -rf *.bak”, problem was I accidentally entered a space between the * and .bak parts as I typed the command in.

    Once rm indicated it could not find the file ‘.bak’ I knew I was in for a late night re-doing my assignment. I guess it taught me the benifits of making backups, even for the most smallest of things.

  4. Pete Verdon says:

    Is noone going to point out how dumb it is that a random user can kill -9 the kernel? 🙂

    I guess killing your (unsaved) PowerPoint presentation would still be quite bad though.