Mr. Roboto

Your First 5 Minutes with Windows PowerShell

Here's how to make your first PowerShell experience a good one right from the outset.

Unless you've been out of the office for the last year or stuck deep in the bowels of your data center, you should know that Windows PowerShell is here and here to stay. Whether you like it or not, this is the management tool you'll need to begin using. But this doesn't have to be a hair-pulling, teeth-rattling process. Mr. Roboto is here to help.

PowerShell is first and foremost an interactive management console: You give PowerShell some instructions, and wonderful things happen. So, let's say you've never seen a PowerShell prompt but you have it installed. Here's how you might spend your first five minutes.

First Minute
The first thing to do is learn how to use PowerShell's extensive help system. At a prompt, type:

Help *

Use the space bar to page through the results. These are all topics that PowerShell can help you with. Pick one and ask for full help:

Help get-service -full

You will get syntax, parameter descriptions and complete working examples. Every cmdlet, PowerShell's command unit, is documented. Run this:

Help about*

These are the topic files that provide more information about things such as the pipeline, functions and remoting. I know some of the names are long, but you only have to type enough of the name so that PowerShell knows what you're after:

Help about_sw

This will display topic information about the Switch construct. Of course, a well-written reference book is helpful, but PowerShell's documentation and help system works well in a pinch.

Second Minute
PowerShell is an object-based shell, unlike the text-based shell of the cmd.exe and Unix/Linux shells. Even though you run a command and see text, what you're really seeing is an object. Try these commands in your second minute:

Get-date
Get-date | Get-member

The first thing you typed is calling the Get-Date cmdlet, which writes the current date and time -- although the details are more complicated than that. The second expression takes the result of Get-Date and pipes or sends it to the Get-Member cmdlet. This cmdlet is designed to tell you everything about an object: in this case, it's a date-time object with a variety of properties. This is helpful because not every property is always displayed. At a prompt type:

Get-process

These are the current processes on your computer. Run this command through Get-Member, and you'll see there are even more properties of a process object.

Third Minute
In your third minute, try navigating around PowerShell. You can use CD to change directories and drives. But PowerShell can do much more. To see all of PowerShell's drives, run this:

Get-psdrive

PowerShell uses different adapters to present different systems as a file system. Try these commands:

cdhklm:\system\currentcontrol 
set\services
dir

You're now looking at the registry on your machine. When finished exploring, change back to your C: drive.

Fourth Minute
A few minutes ago, you experienced your first pipelined expression.

PowerShell's cmdlets are designed for single-purpose tasks such as sorting and filtering. By sending objects from one cmdlet to the next, you can achieve some very remarkable results without writing a single script. You've already seen Get-Process in action. Try this:

get-process | sort workingset 
-descending | select -first 10

With hardly any effort, you have a sorted list of the top 10 processes based on the workingset size. If you have a few moments left, take a look at the About_Pipelines help topic.

Fifth Minute-and Beyond
In your last minute, look at full help for these cmdlets: Where-Object, Select-Object, Out-File, Out-Printer and Get-WMIObject. These are cmdlets you'll be using frequently. From this point on, all you have to do is explore and try things out.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.

Featured

comments powered by Disqus

Subscribe on YouTube