PowerShell: My introduction to Learning PowerShell

I’ve been reading Learn Windows Powershell 3 in a Month of Lunches.  I’m going to do a summary of the chapters I’ve already read, and a more detailed entry on the chapter I’m currently reading.

This book is designed to be read in shorter increments; this is not something that you try to power through and get as much done as fast as possible.  The authors have the idea that you should be able to read this and do the labs in 30-45 minutes, and over a month of lunches you should have a decent grasp on how to use PowerShell.

Chapter 1 and 2 is some introduction stuff to help you get acquanited with basic terminology and getting the shell set up the way you like it.  The most useful things in these chapters is how to set up PowerShell to your preference, and finding out how to determine your version of PowerShell by running $PSVersionTable

Chapter 3 goes over how to use the help file.  PowerShell has a built-in help file that needs to be updated as soon as possible, using the update-help command, in order to get the full experience from PowerShell.  You can query the help file various ways, but the most familiar is just simply typing in help and the command.  If you don’t know the command but know it contains a certain word then help and the word surrounded by the asterisk “*” will search the help file for any commands that contain that word and display the list (ex. help *service*).

Chapter 4 is the chapter I’m doing today; it goes over running commands and the basic structure of them.  Microsoft designed PowerShell with some good ideas in mind, their command structure makes it pretty easy to find a command even if you don’t know exactly what you want to do without ever having to leave the shell (I know how much you like to use Google).  The commands are structured to start with a standard verb, and I’m quoting this from the book, “like Get or Set or New or Pause”, so if you went over chapter 3 now you have a decent idea of how to search for a command.

Some of the commands can get pretty cumbersome so PowerShell has a lot of aliases built into it (you can even set your own using New-Alias), if you want to see if a command you run often has an alias then try the get-alias command (ex. get-alias -definition “get-service” or get-alias -definition *service*).  Aliases function exactly the same as the normally typed out command, they’re just a lot shorter.

An interseting feature built into PowerShell V3 is the Show-Command cmdlet.  This cmdlet opens up a graphical prompt showing the command parameters and allows you to fill them out.

get-command show-eventlog


This was cool enough I took a screenshot

Syntax comes out right every time!

Show-Command only works with single commands so if you’re stringing them together, it can only help with one at a time.

The error handling in PowerShell is pretty useful, too.  Almost every error that you encounter has a good explanation of why it is yelling at you and what it thinks you may have done.  Usually the best idea is to refer back to the help file to see what you did wrong.

Useful commands ran as written:
Search for a parameter alias: (get-command get-eventlog | select -ExpandProperty parameters).computername.aliases
Sends ICMP echo request packets (“pings”) to one or more computers. Test-Connection

Leave a Reply

Your email address will not be published. Required fields are marked *