St. Louis Day of .NET 2011 – PowerShell

This is part of a series of posts containing my notes from the sessions I attended at the 2011 St. Louis Day of .NET conference.

This series does not attempt to give complete accounts of the information presented in each session; it is just a way to capture the bullet points, notes, and opinions that I recorded while attending the conference. I have previously posted a list of all of the session materials and sample code that I have been able to find online, so if you are looking for a more precise account of a session, try looking there.

Following are my notes from the PowerShell – 10 Things You Need To Know session, presented by Matt Hester.  He has posted online far more information than could be covered in one conference session; you can find that material on his blog

One thing that I felt was missing… or that I missed.. from the presentation was an explanation of how to obtain, install, and/or check for PowerShell.  For that reason, my notes jump right into the details of using the tool.

  • Besides being a script environment useful for bulk operations and task automation, Powershell also provides an interactive shell.
  • Everything in Powershell is considered an object.
  • Commands may be cmdlet, alias, or function.  A "cmdlet" is a "normal" command.  An "alias" is an alias for another command.  A "function" is a way to execute a block of commands (and can accept parameters).
  • The "|" operator routes output from one command to the input to another command.  Multiple commands can be connected. 
  • PowerShell is not always consistent about when a dash is needed (ex: "-confirm" vs "confirm").
  • You can use "providers" to access things like Active Directory and the Windows Registry with PowerShell.  (For example:  use "cd AD:" to navigate to the root of the active directory tree on the local machine.)
    Here are the specific PowerShell commands that were covered in the session.

Show the list of PowerShell commands that are available.  This is not ALL PowerShell commands, but all *available* commands… see the next two commands for clarification.

get-module –listavailable
Show all modules that provided PowerShell commands (whether those commands are currently available or not).

import-module <modulename>
Loads a module to make its commands available to the current PowerShell session.

Lists the services on the machine.

get-help <built-in cmdlet name>
Gets information about the named command.

get-help <built-in cmdlet name> – examples
Gets information, including examples of usage, for the named command.

get-service |get-member
List available methods and properties for services on the machine.  Note that the “|” operator is used to send the output of the get-service command to the get-member command.

get-service |out-file <filename>
Send the output of the "get-service" cmdlet to the specified file (text file)

get-service |out-gridview
Send the output of the "get-service" command to a sortable/filterable GUI window. Unfortunately, the window does NOT support copy and paste.

get-service |stop-service –whatif
The "-whatif" parameter will show you what the specified command(s) will do (without actually executing those commands). In this case, the commands will in fact stop all of the services on the machine.

get-service |stop-service –confirm
The "-confirm" parameter will cause the user to be prompted for confirmation that the command should be executed.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: