PowerShell Training: Back to Basics



PowerShell is quickly taking over IT departments and with such big names behind it, it’s no wonder.  If you already use PowerShell, chances are that you have used a module or snap-in from one of the companies below:

Microsoft
VMware
NetApp
Cisco
Intel
Quest

For those not familiar with PowerShell, when they see how quickly or easily things can be configured or automated, they of course want to get in on the action.  So how do you go about introducing someone to PowerShell and make them self-sufficient?  You give them a link to www.ScriptingGuys.com and tell them to study up. But what if I am giving them an in-person demo?  I show them my guide to using PowerShell for the first time and then usually start out with these five* commands:

Get-Command

The first thing that people usually want to know is, ‘What can I do with PowerShell?’  At that point, I load up the console and tell them to type in Get-Command.  A long list of available cmdlets starts scrolling by and you can see their eyes light up.  Once they find a cmdlet that interests them (there always is and most of the time it has to deal with a current issue they are facing), I move on to the next command.

Get-Help

This is my go-to command; I use it more often than any other.  If I ever come across a command that I want to use, but don’t know how, Get-Help is my first stop.  To see more details for a cmdlet, you can use one of the following:

Get-Help -Examples
Get-Help -Detailed
Get-Help -Full
Get-Help -Online

I’ve found that the –Examples switch is the best for beginners, as it gives them an idea of what can be done with the command and lists the information that they need to accomplish the task.  With these two cmdlets, they have more than enough to get started and get some work done.  Once they have had a little bit of practice, I continue on with where it gets really interesting, modules!

Get-Module / Import-Module

As with most IT professionals, you and the trainee have probably worked with a technology from at least one of the companies listed at the beginning of this post.  Did you know that they all provide PowerShell modules or snap-ins that help you automate their products?  To view all modules that are available on your machine, just type Get-Module –ListAvailable at the PowerShell console and you should see a list of each one available and the commands included.  If you were looking for one of the modules from a vendor listed above, be sure to download and install it first, then re-run the Get-Module cmdlet.  Once the modules are installed, you can import them using Import-Module .  Now you can use the commands you learned previously to view each of the cmdlets available in the module and their usage:

Get-Command –Module

Note: Some of the vendors are still providing their cmdlets in snap-ins, which is legacy for PowerShell v1.0.

Get-Member or Format-List

At this point, the trainee should have a general understanding of what PowerShell is and how to use it.  Depending on the background of the person, I tailor the last section for their professional background.  For anyone with a developer background, I typically show them Get-Member, as it shows them all of the methods, properties and other membertypes, which they are familiar with seeing.  For the IT Pros learning PowerShell, I typically stick with Format-List.  This gives them the information system administrators and technicians are looking for and when they are more comfortable, I loop back and show them Get-Member.

And that wraps up my beginner’s guide for PowerShell.  You provide the who and why and I provide the what and how.  ‘When’, you say?  The time for PowerShell is NOW!

Resources:
  1. Popular PowerShell Modules 
  2. Windows Features/Roles that use PowerShell 
  3. PowerShell-enabled technologies

Using PowerShell for the First Time

So you want to use PowerShell for the first time and you can’t figure out where to start.  You right-click on a PowerShell script that you downloaded from the internet and you are prompted with a security warning, or maybe you see some error messages and then the PowerShell window disappears.  Here are some simple advice to make sure your first PowerShell expedition is a successful one.

Make sure you are using the latest version of PowerShell

The PowerShell team has a great blog post which lists all available versions of PowerShell and related downloads.  If you are using Windows 7 or Server 2008 R2, you already have PowerShell 2.0 installed, but if you are using a previous OS, you will need to download the most recent version.  As of this posting, the latest production release is v2.0, which requires .Net Framework Version 2.0 to be installed.  It is recommended to install .Net Framework Version 3.5 SP1, as this is required for the Integrated Scripting Environment (ISE) and graphical cmdlets.

Opening the PowerShell console

There are numerous ways to access the PowerShell console (when installed) and I’ll list just a few of them for you here.

  • Taskbar
    • An icon that looks like a blue square with >_ in white lettering
    • Windows 7 and Server 2008 R2 (by default)
  • Start Menu
    • Start > Programs > Accessories > Windows PowerShell > Windows PowerShell
    • Windows XP/Vista/7 and Server 2003/2008/2008R2
  • Windows Explorer
    • C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    • Windows XP/Vista/7 and Server 2003/2008


Configure the Execution Policy for PowerShell

Configuring the PowerShell execution policy requires access to a user account that has local administrator rights to the system that you wish to configure.  To begin the process, locate the PowerShell executable at one of the locations listed above, right-click the icon and select ‘Run As Administrator’.  If UAC is enabled, you will be required to accept a security warning.  You should now have a blue PowerShell console with a title of ‘Administrator: Windows PowerShell’.  To see the current execution policy, you can use the Get-ExecutionPolicy cmdlet.  In a default install of PowerShell, the value Restricted will be returned. To change the policy, use the Set-ExecutionPolicy cmdlet. 

For more information on available execution policies and how your system will be affected, you can read the about_Execution_Policies documentation.

Microsoft Community Contributor Award

Hi again everyone.  Just stopping by to give some good news.  I was awarded as a Microsoft Community Contributor for 2012!  Although they don't go into great detail as to what you were awarded for, I'm assuming that it was for my contributions to all aspects of TechNet (forums, gallery, wiki and blogs).  Here is my shiny new MCC logo:



Click this link to check out my TechNet profile and see my contributions.