Introducing: New PowerShell Language Enhancements
First of all, let me thank those of you that have adopted the Ad-Supported version of Get-ChildItem that we introduced last year. The additional revenue has proven quite effective for reducing world hunger, improving world peace, and providing spinner rims to those in need. In fact, several of you did indeed meet fun young DLLs in your area. As just one example of many, Jeffrey Snover recently announced his engagement to shell32.dll! Congratulations guys!
Anyways, back to the topic at hand. One thing we’ve sometimes heard is that the PowerShell scripting language is too complex – the dizzying array of cmdlets, control statements, and keywords is enough to make many shy away.
We’ve been listening, and have quietly been developing a significant language enhancement package to eliminate this complexity.
Take, for example, just SOME of the different ways to do a “count down” in PowerShell
- dir $ENV:WINDIR\System32\*.dll | % { $_.Length % 11 } | Sort -Unique -Descending
- $counter = 10; while($counter -ge 1) { $counter; $counter = $counter - 1 }
- for($counter = 10; $counter -ge 1; $counter–) { $counter }
- foreach($item in 10..1) { $item }
- 10..1 | Foreach-Object { $_ }
- 10..1 | Foreach { $_ }
- 10..1 | % { $_ }
- 10..1
Right there, you have EIGHT opportunities to make a mistake. Who needs all of those options, when all you want is to count down from 10 to 1?
As a solution to this conundrum, we’ve developed a new subset of the language that supports only the minimal statements required to make a program. Working in this language is like working at a conveyor belt, or with the tape in a cassette tape. You can:
- Move the tape left
- Move the tape right
- Look at what’s in front of you on the tape
- Compare what’s in front of you with something you already know
- Put something new in front of you on the tape
That’s it. Using these techniques alone, you can develop any software that can be written for a computer. Think of some fun applications!
- Rocket guidance software
- A Microsoft Windows emulator
- A new object-based, conveyor-belt-based shell!
Just to give you an example of how simple and intuitive this language is, here is a program that counts from 25 to 1:
[C:\temp]
PS:28 > . c:\temp\KBB04012007.ps1
[C:\temp]
PS:29 > $actions = @(
>> ## Current State See Put Move New State Debug Output
>> ,@("initial", "1", "1", "Right", "scan_right_work", "")
>> ,@("initial", "0", "0", "Right", "scan_right_no_work", "")
>> ,@("scan_right_no_work", "0", "0", "Right", "scan_right_no_work", "")
>> ,@("scan_right_no_work", "1", "1", "Right", "scan_right_work", "")
>> ,@("scan_right_no_work", " ", " ", "Right", "done", "")
>> ,@("scan_right_work", "0", "0", "Right", "scan_right_work", "")
>> ,@("scan_right_work", "1", "1", "Right", "scan_right_work", "")
>> ,@("scan_right_work", " ", " ", "Left", "at_end", "")
>> ,@("at_end", "1", "0", "Left", "reset", "")
>> ,@("at_end", "0", "1", "Left", "scan_left", "")
>> ,@("scan_left", "0", "1", "Left", "scan_left", "")
>> ,@("scan_left", "1", "0", "Left", "reset", "")
>> ,@("reset", "1", "1", "Left", "reset", "")
>> ,@("reset", "0", "0", "Left", "reset", "")
>> ,@("reset", " ", " ", "Right", "initial", "Next Number ^^")
>> )
>>
[C:\temp]
PS:30 > Initialize "11001"
[C:\temp]
PS:31 > "Initial tape: $tape"
Initial tape: 11001
[C:\temp]
PS:32 > RunProgram $actions
[C:\temp]
PS:33 > "Final tape: $tape"
Final tape: 00000
Enjoy. Attached is a pre-release version of KBB04012007 that will be released next patch Tuesday.
KBB04012007.ps1.txt (26.18 KB)
[Edit: Alas, another change not meant to be. Perhaps in version 2. Happy April Fools' :)]