Windows

PowerShell 3 takes scripting to new heights

Scott Lowe takes the early preview version of PowerShell 3.0 for a spin and likes what he sees. Here are some of the best-looking new features from his test run.

Okay, I might be exaggerating when I say that the upcoming version of PowerShell, Microsoft's robust and ubiquitous scripting language, will bring scripting to 2015, but PowerShell 3.0 will certainly bring a whole lot to the table for both hardcore programmers as well as casual scripters. Personally, I fall somewhere in the middle and I'm pretty excited about what I see coming.

First of all, PowerShell 3.0 is included in the Windows Management Framework 3.0 CTP2, which is available for download and installation on Windows 7 SP1 and Windows Server 2008 R2 SP1 machines. Now that you know where to get it, make sure you understand that "CTP" stands for Community Technology Preview. This is pre-alpha stuff. It's from beta. It's intended to be exactly what it says... a preview. Don't expect a finished product and certainly don't expect something that is free of potential problems. You shouldn't install the CTP version to a machine that you depend on for critical, time-sensitive PowerShell scripting. I installed the CTP2 to a test virtual machine. In order to do so, I needed to make sure that the machine was running Windows 7 SP1 or Windows Server 2008 R2 SP1. Further, CTP2 requires the installation of the .NET Framework 4.0.

Once you have the prerequisites in place, you can install the package. To make sure everything has gone as planned, open PowerShell after installation and run the command $host.version. You will get a result like the one shown in Figure A, which shows you that PowerShell 3.0 is installed.

Figure A

PowerShell 3.0 is installed

Before I show you a couple of pretty cool capabilities in PowerShell 3.0, let's take a look at what Microsoft is saying they're including in this newest version. From the Windows Management Framework 3.0 - Community Technology Preview (CTP) #2 page, here are some of the new features in Windows PowerShell 3.0:

  • Workflows: Workflows that run long-running activities (in sequence or in parallel) to perform complex, larger management tasks, such as multi-machine application provisioning. Using the Windows Workflow Foundation at the command line, Windows PowerShell workflows are repeatable, parallelizable, interruptible, and recoverable.
  • Robust Sessions: Robust sessions that automatically recover from network failures and interruptions and allow you to disconnect from the session, shut down the computer, and reconnect from a different computer without interrupting the task.
  • Scheduled Jobs: Scheduled jobs that run regularly or in response to an event.
  • Delegated Administration: Commands that can be executed with a delegated set of credentials so users with limited permissions can run critical jobs
  • Simplified Language Syntax: Simplified language syntax that make commands and scripts look a lot less like code and a lot more like natural language.
  • Cmdlet Discovery: Improved cmdlet discovery and automatic module loading that make it easier to find and run any of the cmdlets installed on your computer.
  • Show-Command: Show-Command, a cmdlet and ISE Add-On that helps users find the right cmdlet, view its parameters in a dialog box, and run it.

I'm not going to focus here on the behind-the-scenes stuff; I'll instead focus on a couple of features that will make life easier for both new and experienced PowerShell scripters.

Some features require the use of the PowerShell Integrated Scripting Environment (ISE), which can be installed as a feature from Server Manager as shown below in Figure B.

Figure B

Install the PowerShell ISE tool from Server Manager
Perhaps one of the most useful features added to PowerShell 3.0 is a great new Show-Command cmdlet, which leverages the aforementioned ISE tool in a way that makes it much, much easier to locate commands and understand required and optional parameters. Shown in Figure C, note that you can search for a command, select it, and be shown all of the parameters that are necessary and optional. The required parameters have an asterisk next to them. You can also make use of PowerShell's Confirm and WhatIf capabilities right from this window.

Figure C

The Show-Command window
The next feature isn't really new, but has been made even better in PowerShell 3. The out-gridview parameter is shown in Figure D. With this, you can overcome PowerShell's text-based limitations and display tabular results in a graphical grid-based view, which allow you to adjust column size, add parameters and more. In Figure D, note that I've added two parameters at the top of the window. I can use these to narrow the displayed results. When necessary, I can then just click the X next to a parameter to remove it from the grid. The command that I used in Figure D is get-process | out-gridview.

Figure D

PowerShell's grid view feature

Summary

These two user-facing features are just the tip of the iceberg when it comes to new ways that PowerShell can be used to ease administrative burden. Between these and the behind the scenes features, such as workflows and robust sessions, Microsoft has really taken PowerShell to a whole new level.

About

Since 1994, Scott Lowe has been providing technology solutions to a variety of organizations. After spending 10 years in multiple CIO roles, Scott is now an independent consultant, blogger, author, owner of The 1610 Group, and a Senior IT Executive w...

6 comments
rthrelkeld
rthrelkeld

The out-gridview shows the CPU seconds and several other fields as strings. So hitting the column header sorts them in string order. 1234 seconds appears before 2.34 seconds.

jsnover
jsnover

One of my favorite new features is the -PASSTHRU parameter on Out-Gridview. Try this: get-service |out-gridview -PassThru |start-service -Verbose Then select the services that you want and when you click OK, the selected services will get passed down the pipeline to the Start-Service cmdlet. Fun. Jeffrey Snover [MSFT] Distinguished Engineer and Lead Architect for Windows Server

Craig_B
Craig_B

Here's an article from Prof. Powershell that explains how to run PowerShell 2.0 and 3.0 side by side on the same machine. http://mcpmag.com/articles/2011/12/20/powershell-2-and-3-side-by-side.aspx Basically after installing PS 3 CTP if you run: powershell.exe -version 2.0 which will start a PS 2 session. On a side note: I could not post this response from IE9 and had to use Firefox 9 to post.

cbstryker
cbstryker

"This is pre-alpha stuff. It???s from beta." You do realise that alpha comes before beta? How can it be "from beta" if it's "pre-alpha stuff."?

patthew
patthew

I think it might've been a typo and the writer meant to say "FAR from beta"