Path PowerLine

I am constantly impressed by how quick you can get the job done with PowerShell. As I have mentioned before one-liners, or PowerLines as I prefer ;) are a good example, although not always practical.

So here’s my PowerLine for the day:

if (! ($env:path).contains(“C:\coding”) ) { $env:path+= “;C:\coding” }

This basically checks if the path statement contains “C:\coding”, and if not appends it to the end.

I haven’t looked at a PowerLine for removing it yet, but I suspect one line might be pushing it for that. Anyone fancy the challenge?

Power Lines

Once you’ve been using PowerShell for a while you start to notice that you can often get the job done using just one line of code. These “one liners” can sometimes look pretty impressive, but they are also get pretty cryptic!

Its a good sales pitch for PowerShell: “yeah, I can do [insert amazing feat here]. It just takes a line of code in PowerShell!” ;)

I like to think of these, as small bragging rights for the new language, and I call them Power Lines. As I find interesting Power Lines during my wanderings I will start posting them here.

Of course the most impressive Power Lines I’ve seen around originate from developers, so I make no promises on the “amazement” factor ;)

Starting off small here’s the first one that I’ve been using today:

[system.guid]::NewGuid().ToString()

This simply generates a new GUID in string format.

A couple of other examples I’ve seen around:
MS PowerShell One Liners
MOW’s old blog
Google

What’s your Power Line?