Prof. Powershell

PowerShell vNext is vBest

Three good reasons to like the next version of PowerShell.

Unless you've been hiding in a bunker recently, I'm sure you've heard about Windows 8 and the release of a CTP for PowerShell 3.0. If you've been trying to avoid PowerShell I think you'll find that hard to do once PowerShell 3.0 and Windows 8 ships. Even if you don't intend on migrating to Windows 8, you will want to deploy the PowerShell v3 bits.

PowerShell is now bundled as part of the Management Framework, which also includes WinRM for secure remote management and an updated version of WMI. PowerShell v3 may finally be the version that gets admins off the sideline and into the game. Here are my top three reasons why:

Simplified Language
In PowerShell v2 we wrote expressions like this:

PS C:\> Get-service | where {$_.status -eq "running"}

This will continue to work in v3, but now you can use a much simpler language and one that doesn't rely on the cryptic $_.

PS C:\> Get-Service | where status -eq "running"

Here's another example, and yes I know this isn't the way you would really accomplish this task, but it illustrates the point:

PS C:\> ps | where name -eq notepad | foreach kill

Or you can use the new $PSItem automatic variable.

PS C:\> "foo","bar" | foreach {$PSItem.ToUpper()}
FOO
BAR
PS C:\> Dir $env:temp -file | where length -gt 1mb | select Fullpath,@{Name="Size";Expression={$PSItem.length}}

A number of cmdlets have also been improved, like Get-Childitem which now can easily display files by attribute such as system and hidden.

Robust Remote Sessions
In PowerShell v2 when you established a remote session it was subject to the whims of your network. If the connection dropped you essentially had to start all over.

In v3 we now have very robust sessions. In fact, you can start a session, kick off some commands and return to your prompt. When you start a new PowerShell session, even on a different computer, you can connect again to the same sessions.

Jobs and Tasks
PowerShell takes background jobs and tasks to a whole new level. We still have background jobs, but now you can pause and resume jobs. PowerShell v3 also can interact directly with the Task Scheduler so that you can create PowerShell based tasks:

$trigger=New-JobTrigger -At 06:00 -DaysOfWeek Friday -weekly
Register-ScheduledJob -name "FridayJob" -ScriptBlock {dir $env:temp -rec | out-file c:\temp.txt} -Trigger $trigger

This job is persistent because it is registered with the task scheduler and not just PowerShell.

Frankly, there are many, many exciting features and we'll be exploring more of them in 2012, especially as the final release date nears

So what should you do now? First, don't put off learning PowerShell. The more you can learn now, the easier it will be to pick up the new features when v3 finally ships. At the same time, setup the v3 CTP bits in a test environment so you can start getting a feel for them. Remember, we're only at a CTP so things can and will change.

You can download the Management Framework 3.0 CTP 1 here.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular