Ezine 166 – Learning PowerShell

Ezine 166 – Learning PowerShell

This ezine is dedicated to persuading people to try PowerShell.  I am not selling anything!  You need no money, just the inertia to download the free PowerShell files from Microsoft’s site; then try a few of my basic ideas and examples.

Topics for PowerShell in Exchange 2007


This Week’s Secret

Don’t believe that PowerShell is just for Exchange administrators, nor is it just for running ‘DIR’ commands.  Equally, don’t think –  ‘Those process commands are flashy, but are nothing like the real world’.  I say again, PowerShell is the way of the future, you are limited only by your own imagination, it’s the sort of language to dip in to as and when you need a solution to a computer configuration or interrogation problem.

If you have already started learning PowerShell, be patient with me, this week I want to tempt more people into the community.  Just as anyone can hit a tennis ball with that big racket, so anyone can type a PowerShell command.  Just as only one in a million are good enough to play tennis at Wimbledon, so few are good enough at PowerShell to become gurus.  My point is PowerShell is easy to learn the basic strokes and enjoy the game, yet it has all the intricacies you would expect from a top notch game – sorry, I mean script language.

Who Will Benefit From PowerShell?

I have an overwhelming sense that PowerShell is the future way to configure at least some of your computer settings.  At the very least I am sure that PowerShell will replace the aging ‘DOS’ shell.  In my minds eye I see at least three distinct groups of PowerShell learners who will benefit from this scripting language.

1) Whenever configuring a setting via the command-line is faster than the GUI, then people will always be attracted to the language.  Exchange Administrators have good reason to learn the rudiments of PowerShell syntax, in particular the -parameter to modify the main verb-Noun cmdlet.  Even if you have no desire to use Exchange 2007, this concept of administrators configuring items by typing instead of clicking the mouse will spill over into Windows Server 2008 and its successors.

2) People will transfer from VBScript to PowerShell, particularly if they want better control over WMI.  (Windows Management Instrumentation).  The biggest benefit is efficiency; PowerShell constructions are shorter and less fussy than the equivalent VBScript commands.

3) As an ‘old timer’, I must also take into consideration those just starting out in computing.  Newbies have the advantage of no baggage from DOS or other ancient systems, consequently they will probably learn PowerShell faster than any of us.  One of the best ways to practice with PowerShell is to get basic information about a) files, b) services, or c) processes.  For example try these three commands:
a) get-Childitem c:\
b) get-service *
c) get-Process |ft ProcessName, cpu -auto

?) Budding programmers who want to develop applets using PowerShell.  This is an area where I confess to being a bit of a dreamer.  More so as my website is geared to the generalist, rather than the professional programmer.  Nevertheless, I want to plant the idea for prospective script writers to choose PowerShell as a vehicle for writing their programs.  My dream is that eventually such script writers will do us all a favour by producing nifty applets.

Guy Recommends: The Free IP Address Tracker (IPAT) IP Tracker

Calculating IP Address ranges is a black art, which many network managers solve by creating custom Excel spreadsheets.  IPAT cracks this problem of allocating IP addresses in networks in two ways:

For Mr Organized there is a nifty subnet calculator, you enter the network address and the subnet mask, then IPAT works out the usable addresses and their ranges. 

For Mr Lazy IPAT discovers and then displays the IP addresses of existing computers. Download the Free IP Address Tracker

PowerShell’s Patterns

The first pattern to observe is that each PowerShell cmdlet starts with a doing word like, ‘get’, ‘set’, or ‘start’; this verb is followed by an object, like ‘service’, ‘process’, or a myriad of other operating system handles with strange names.  The result is a basic cmdlet, for example, get-process, or start-service alerter.  Incidentally, top programmers use only about ten of these verbs, however, they have a huge bank of nouns.

The second pattern to research is the -parameter.  Once you have a cmdlet pair the trick is to gain precise control by appending a modifier or -parameter.  For example, -name, -path or -recurse.  Here is an example which lists all the files under the system32 folder:

get-childitem -path c:\windows\system32\ -recurse

(Recurse means drill down through the sub-directories).

The third pattern to master is PowerShell’s signature tune – the pipe symbol (|).  This tiny symbol means make the output of the first section | the input of the second section.  For example, list files | send the list to this file:

get-childitem -path c:\windows\  | out-file c:\windows.txt

Note 1: Look in the c:\ root directory for a file called windows.txt

Note 2: You could change the path to: -path c:\windows\system32\ -recurse

PowerShell Strategies and Scenarios

It would make my day if you experiment by using PowerShell for as many different types of task as possible.  But don’t follow me slavishly; develop your own PowerShell agenda.  Here are ideas of how to employ PowerShell:

  • Repetitive tasks.  Change an Active Directory parameter for different users.
  • Research.  Find files containing a particular phrase.
  • Interrogating the operating system with WMI.  How long have I got!  If you have used WMI with VBScript it will be MUCH easier in PowerShell.
  • Type at the command-line, because the GUI takes longer.  For example, Exchange 2007 configuration.
  • Replace ‘DOS’ commands.  PowerShell invokes built-in commands such as Ipconfig or NetSh.

Installing PowerShell

Your strategy for installing PowerShell varies depending on your underlying operating system.  Much of the of PowerShell’s richness comes from .Net framework, thus its no surprise that installing .Net framework is a pre-requisite to installing PowerShell.  However, watch out for version conflicts if you add .Net Framework, 2.0 or 3.0 when you already have applications using version 1.1.

  • Windows Server 2008 – Add Feature (PowerShell is built-in, but dormant by default)
  • Vista, XP, Windows Server 2003.  Each of these operating systems requires that you download a slightly different version from Microsoft’s site.  Remember to install .Net framework first.

As of June 2008, the current version is PowerShell 1.0.  While there is a CPT v 2.0 (Community Technology Preview) under development, Guy says stick with the tried-and-tested version 1.0 until a fully functional version of 2.0 is released.  While learning you want success, and that means a solid foundation with no flaky new features.  The main advantage of version 2.0 will be remote scripting, but that’s not a feature you need at the very start of your PowerShell career.

Go to Microsoft’s Download Site

More Resources for PowerShell

A sign that PowerShell is growing in popularity in the number of books, forums and add-ons that enthusiasts have developed.  While I have bought two books, I cannot recommend either.  My message is no book can cover all of PowerShell, thus make sure that any book you buy covers the sections that you are interested in.


  • Microsoft.Public.Windows.PowerShell
  • PowerShellCommunity.org
  • powershelllive.com/forums/49/ShowForum.aspx

Microsoft’s script center, Microsoft’s PowerShell Documentation Pack. Add-ons Quest: QAD. 537

Guy Recommends: Tools4ever’s UMRAUMRA The User Management Resource Administrator

Tired of writing scripts? The User Management Resource Administrator solution by Tools4ever offers an alternative to time-consuming manual processes.

It features 100% auto provisioning, Helpdesk Delegation, Connectors to more than 130 systems/applications, Workflow Management, Self Service and many other benefits. Click on the link for more information onUMRA.

Summary of Learning PowerShell

PowerShell is one of those notions where you have to believe before you can see.   Believe PowerShell is the way of the future and you will see opportunities every time you sit down at your computer.

If you like this page then please share it with your friends


See more Windows PowerShell tutorials

PShell Home   • Introduction   • Dreams   • 3 Key Commands   • PowerShell Help About   • Get-Help

PowerShell v 3.0   • Set-ExecutionPolicy   • Get-Command   • Cmdlet scripts   • Import-Module

PowerShell Version Check   • Backtick   • PowerShell examples   • PowerShell ISE   • Get-Member

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.