Producing an Intentional BSOD (Blue Screen of Death)

I came across the following website the other day

Get-process | Stop-Process

..and it reminds me both some key concepts of PowerShell as well as Don Jones and Jeffrey Snover demonstrating cmdlet binding in this video (@25 minutes)

The first concept is “Read Help!”

Get-help Stop-Process -Full

On Windows Vista and later versions of Windows, to stop a process that is not owned by the current user, you must start Windows PowerShell with the “Run as administrator” option. Also, you are prompted for confirmation unless you use the Force parameter.

The help of Powershell confirms that it’s not as straightforward as the above the above blog post assumes.
The above piped cmdlets won’t generate a BSOD because the vast majority of cmdlets that modify the system will ask for confirmation by default.

Of course pressing “A” is a bad idea as it really ends with a BSOD:

The second concept is “when in doubt, use a risk management parameter”.
To simulate and see what these commands would do, you just need to add the -Whatif parameter:

Get-process | Stop-Process -WhatIf

Wait, there’s another crucial thing here. I said

the vast majority of cmdlets that modify the system will ask for confirmation by default

Powershell’s default behavior is controlled by preferences variables.

Get-help about_Preference_Variables

So, if you want the default behavior (and you should really stick to it), don’t alter these preferences variables.

One of the most widely spread error is people starting a script by doing

$ErrorActionPreference = "SilentlyContinue"

Repeat after me, “this is wrong!

Now let’s go back to one of the most important concept of Powershell: CmdletBinding

Jeffrey Snover quickly explained it in the above video I mentioned (~@30 minutes).

Powershell MVP Don Jones has a great nice example to explain it.

Can you figure out what this will do?

Get-Service | Stop-Process -WhatIf

Let’s have Don Jones explain how CmdletBinding works:

ByValue (Plan A)

ByPropertyName (Plan B)

Want to go deeper, here are some insightful links:

Leave a Reply

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

You are commenting using your 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