Tuesday, March 1, 2011

PowerShell math shortcut

So I'm using PowerShell as a calculator - I mean, why not, right? I've got the window open, and it's great for quick "What's the size of the LUN again?" sorts of questions. It's also really good at telling me the cost of things on a monthly basis.

For example, if you're spending $10/week on coffee, and you want to know how to figure that as a monthly cost, you'd multiply 10*4.3 in the PowerShell prompt for an answer of 43.

However, what if you want to find out how much it would be if you spent $12.50 a week? Rather than type in the full equation of 12.50*4.3, you might think you could use the last-tag-in command, or $$.

But instead, if you put $$*12.5 in the prompt, and hit enter, PowerShell returns that string 12.5 times, or

This appears because PowerShell is treating the last tag as typeless, with a default value of text.