Craig Forrester

The Pleasure of Finding Things Out

github linkedin email rss
Interactive PowerShell, Part 1: The Hidden Shell
February 13, 2018
4 minutes read

A Shell? What’s That?

Most of us that know PowerShell know it as an automation tool — as a way to get remote systems to do things in repeatable ways.

But for as many of us that know the scripting-side of PowerShell, I venture that far fewer know and use PowerShell as an interactive shell. Sure, we may occasionally use it as Command Prompt replacement, but are we truly harnessing the full capacity of PowerShell as a shell?

In my experience, most Windows systems administrators only use the command prompt when they have to — typically to run a script or a one-off command. And, honestly, you can’t blame them. Historically, Windows has had really poor native command line tools. CMD has always been missing the most basic of conveniences that virtually all UNIX shells enjoyed, making interactive use really frustrating; and Windows commands suffered from a lack of consistency — in syntax, in structure, in support from version to version, and in their inputs and outputs.1 I could go on, but suffice it to say that if you’ve been a Windows sysadmin, no one could really blame you for avoiding the command prompt…

That all has changed with PowerShell.

The Hidden Shell Within PowerShell

Now that Microsoft has put PowerShell on every modern version of Windows and Windows Server, there’s no longer any reason for anyone to avoid the command line in Windows.2 There is now an extremely powerful, versitile, fully-functional shell on every Windows system. My aim in this series of posts is to show you that PowerShell is not just an excellent scripting language, but is also a fantastic interactive shell as well — easy enough to use for fast command line work, and powerful enough to compete with anything you’re doing with graphical tools. If you’re a UNIX or Linux admin, I want to convince you that PowerShell is on par with your favorite UNIX shell too (and may even have some advantages).

The Meat Inside the Shell

PowerShell offers a lot of convenience without much work at all, once you understand some basic concepts, like the object pipeline.

For example, say that we want to know what day of the week Christmas falls this year:

# Start by getting the date and time of Christmas
Get-Date "12/25"

# Now all we have to do is select the Day property of the result
Get-Date "12/25" | select DayOfWeek

# If we don't know that property exists, or don't want to type it out,
# we could just put parentheses around our original command
# so that we can access it as an object and access its properties
(Get-Date "12/25").DayOfWeek

This last command lets us use tab-completion on the original command. We just have to surround the command line with parens, type a dot (.) and then press tab to cycle through the properties and methods on the object.

I’ll talk about properties, methods, and the object pipeline in more detail later, but this demonstrates how easy it is to get information from PowerShell and manipulate it.3

How to Follow Along

For the duration of this series I will be using PowerShell 5.1 on Windows 10. If you would like to follow along, and don’t have it installed, you can download and install the Windows Management Framework version 5.1 on your computer.

Don’t know what version of PowerShell you’re running? Try this at your PowerShell prompt:

$PSVersionTable

Your PowerShell version is the value of PSVersion in the output:

Name                           Value
----                           -----
PSVersion                      5.1.14393.1944

That’s it for now. Next time, we’ll talk about how to add custom aliases to make typing commands interactively a lot faster.


  1. One could argue that UNIX commands suffered some of the same but, based on my experience, I would argue that the degree that they suffer those issues is profoundly less severe. [return]
  2. Actually, Microsoft has done more than that. They’ve not only released major improvements to the Command Prompt (cmd.exe), but they’ve gone so far as to create an entire subsystem to bolt true, unported Linux binaries into the Windows environment with “Windows Subsystem for Linux.” [return]
  3. And for you UNIX folks that would normally type something like date -d '2018-12-25', hang tight. One thing you’ll like about PowerShell cmdlets is that they have common features and syntax that make remembering (or rediscovering) them easier. In contrast, ask yourself if you recall the syntax for converting timezones with date off the top of your head, and I think you’ll get what I’m driving at. [return]

Back to posts