Bash-like Tab Completion in PowerShell

[Edit 10/2/2015] - PowerShell 5.0 now includes a new and amazing PSReadLine module by default. You can also install it from here: https://github.com/lzybkr/PSReadLine.

When PowerShell first came on the scene, Unix folks were among the first to notice. They’d enjoyed a powerful shell and a vigorous heritage of automation for years – and “when I’m forced to use Windows, PowerShell rocks” was a phrase we heard many times. This natural uptake was no mistake. There are many on the team that come from a deep Unix background, and similarities to traditional Unix shells were no mistake.

Scripts in the PowerShell Cookbook?

The third edition of the PowerShell Cookbook is getting close! We should have an online preview ready for your perusal in the near future – stay tuned for an update.

One “problem” we’re running into is its size. This is where we’d love some feedback.

We could make it thinner and cheaper by not printing the scripts, but instead hosting them online. That would mean, of course, that you can’t just sit back and read through the sample code.

'Whilst' keyword in PowerShell

Recently, SMBC Comics made the comment that, “In Britain, they have whilst loops, which do not terminate until the Queen says it’s appropriate.

If you are a programming language aficionado, you may recognize this keyword chiefly from languages of P-Celtic (especially Common Brythonic) origin.

One thing you may not know is that the PowerShell team has a huge Canadian contingent. There have been many Canadians responsible for PowerShell’s success, and early tab completion implementations automatically expanded “o” to “ou”. For example, Set-ConsoleColo<TAB>.

A Poor Man's Profiler with PowerShell and CDB

Will Steele asked today on Twitter how we did the analysis to come up with this post on the PowerShell blog in 2009. In brief, it’s a blog post that addressed some performance issues in the .NET framework that were causing Get-ChildItem to be slow. How did we know it was the .NET APIs slowing us down?

The answer came from Visual Studio by way of Software Profiling. Surprisingly, there aren’t many resources for this on the Internet – but here’s a good one: http://msdn.microsoft.com/en-us/magazine/cc337887.aspx.

Sea Foam really works

As a background, I’ve been having a “ghost in the machine” on and off with my motorcycle for a few years. It’ll start idling more roughly, run hotter than usual, give less power than usual, and have these significant non-linear jumps in engine noise / effort at around 7k RPM.

I bought the bike at a shop that has since closed, and for a long time it was under warranty. One time I brought it in, and they replaced some jet seals (or something like that), because it was a common issue with the model (2007 Yamaha YZF600R). It seemed to get better, and then came back. Brought it in again, and they cleaned the carbs, changed the fuel, and things got better. And then it came back. They started blaming old / crappy fuel, but I ride the bike at least a few times per week. I tried switching to fancy gas for a while (Shell / 76 instead of AM PM), and it still came back.

Queueing Theory for the Busy PowerShell Admin

The biggest scripting event of the year is getting close to wrapping up - Scripting Games 2012! There have been a ton of great challenges, a ton of great competitors, and a ton of great commentary.

As one of the guest commentators, I was asked to write a script to monitor uptime on servers in the environment.

To make this as efficient as possible, the solution leveraged WMI jobs to process 32 computers at a time. What’s most amazing about Windows PowerShell jobs running 32 tasks in parallel is not that it makes things 32 times faster. It’s that it makes them even faster than that! The reason is a branch of computer science called “queueing theory.”

MakerBot Replicator Rainbow Color Pack Group Buy

If you own a Makerbot Replicator, you might have seen some of the amazing colours they offer: http://store.makerbot.com/plastic/1-75mm-filament.html.

image

Unfortunately, trying to get a full colour palette (13 colours in stock) means having so much plastic you’ll never get through it all. Makerbot tried offering rainbow colour packs before, but they are now no longer for sale. I suggested it again via email, but it sounds like they’re pretty slammed with making Replicators :) 

How to Download an Entire WordPress Blog

Sometimes, you stumble on a blog that is so chock full of information that you revel in its every word. And then you realize their archive goes back 5 years!

image

I’ve read a bunch of great posts on Nate Lawson’s awesome security blog, and decided that I wanted to read it beginning to end.

If you are the owner of said WordPress blog, the solution is easy – use WordPress’ built-in Export feature. There are even handy services that will turn this into a PDF, eBook, or even printed book.

A Celebration, if You Can Figure it Out

We were talking about a very cool astrological date on the internal PowerShell mailing list recently. In celebration of this event, Josh Rowe made this brilliant comment. See if you can figure out what it does :)

clear;$00=(0..1250|%{9608}),(0..7645|%{9617})|%{$_};(-10..29)|
%{$OO='';$O0=$_;-10..64|%{$0O=$_;$OO+=[char]($00[$0O*$0O-48*$0O+
1720+4*$O0*$O0-96*$O0],@($00[$0O*$0O-52*$0O+1644+4*$O0*$O0-88*
$O0],9617,9617)[(0,1)[($0O-lt28)]+($O0-gt12)])[(0,1)[$0O-gt24]*
($O0-lt14)]};$OO};0..573892165|%{$OO=@((($OO+0)*4*$_*$_/(4*$_*
$_-1)),1d)[$_-lt1];write-progress ":-)"($OO*2)}

I suppose that’s not really fair. Here it is in all of its syntax-highlighted glory:

clear;$00=(0..1250|%{9608}),(0..7645|%{9617})|%{$_};(-10..29)|
%{$OO='';$O0=$_;-10..64|%{$0O=$_;$OO+=[char]($00[$0O*$0O-48*$0O+
1720+4*$O0*$O0-96*$O0],@($00[$0O*$0O-52*$0O+1644+4*$O0*$O0-88*
$O0],9617,9617)[(0,1)[($0O-lt28)]+($O0-gt12)])[(0,1)[$0O-gt24]*
($O0-lt14)]};$OO};0..573892165|%{$OO=@((($OO+0)*4*$_*$_/(4*$_*
$_-1)),1d)[$_-lt1];write-progress ":-)"($OO*2)}

PowerShell Book Reviews

There have been a handful of useful posts recently giving reviews across the spectrum of PowerShell books. I always love reading these posts, as they let you compare and contrast the whole range of quality and approaches. When reading reviews that focus only on a single book, it’s sometimes hard to calibrate – does the reviewer get this excited about blank reams of paper? Slag Shakespeare for his typos?

My favourite is Richard Siddaway’s summary, freshly updated today: http://richardspowershellblog.wordpress.com/2012/03/11/powershell-booksmarch-2012/. The ecosystem of PowerShell books has really blossomed – I love that there are two books on managing VMWare on this list!