« Vim 7.2 Released | Main | Molokai for Vim »
I thought it would be fun to bring up a list of some small things I love about using PowerShell as my default command line / scripting tool on the Windows platform. Without further introduction, here they are:
One of the most annoying limitations of the old cmd.exe was that it provided almost no support for network shares that were not mapped as drives.
The PowerShell provided model, fortunately, didn't make this mistake, so you can use set-location to switch to a network share and execute commands there just like in any other local folder:
Like other shells, PowerShell supports pushing folders into a stack and then popping them back out, making it a lot easier to navigate around a few folders without having to remember the complete paths each time. You manipulate the location stack using the push-location and pop-location commands, which are aliased to pushd and popd respectively.
I find this very useful when running doing builds or when working with Vim and some scripting language.
The PowerShell implementation, however, has a couple of advantages:
The contents of the location stacks are stored as part of your PowerShell Session State, and you can see the contents of each stack by using the get-location command:
Notice that the default stack will always have an empty string ('') as its name.
The fact that PowerShell is based on the .NET Framework can be confusing to some people due to some of the underlying complexity of the framework leaking to the shell (like value types).
However, for a developer like me, this is a great thing. It means that a lot of the things I used to create small C# apps for, like quickly trying out a framework class/method, I can now try interactively on the shell. It also means that there is a lot of functionality already built, right at my fingertips that can be used very quickly.
Here's an example: I was recently working on a new Virtual Machine I had just setup and needed to generate a new GUID. I'm very used to going to the command line and running the old uuid.exe utility to do this, but, unfortunately, I had not installed the Windows SDK on the VM yet and was not planning to. With PowerShell, though, this was not a problem:
# uuidgen.exe replacement function uuidgen { [guid]::NewGuid().ToString('d') }
Another aspect that I really enjoy about PowerShell is the built-in introspection features. It's a lot easier to learn the shell when all the information about what's available and the objects you're manipulating is easily accessible.
Here are some of the introspection features I like:
get-command
"ls function:"
"ls variable:"
$MyInvocation
$ExecutionState
$Host
I used to constantly start calc.exe to do a quick calculation. Since PowerShell is a full scripting language, however, I now do most of those quick calcs by directly entering expressions into the PowerShell prompt.
It's a heck of a lot easier and very convenient for me since I always keep around a PowerShell prompt opened and ready to go.
Tomas Restrepo is a software developer located in Colombia, South America. His interests include .NET, Connected Systems, PowerShell and lately dynamic programming languages. More...
email: tomas@winterdom.com msn: tomasr@passport.com
Copyright © 2002-2008, Tomas Restrepo.
Powered by: newtelligence dasBlog 2.2.8279.16125