Thursday, October 24, 2013

Replace PowerShell with the Command Prompt–But WHY?

I get a customised Google News page which brings up, amongst other things, recent news about PowerShell. This is a nice way of keeping up to date with news specifically about PowerShell and other things I am interested in.

This week, the applet I use to get news brought up an article entitled Replace PowerShell with the Command Prompt. I immediately clicked the hyperlink to discover details on how to change the Win+X Menu in Windows 8.1 back to Cmd.Exe.

WHY??? I felt myself asking! WHY Why anyone actually want to go backwards. A bit like replacing Notepad with a link to Edlin (or VI) if you ask me. Almost all the traditional command line tools work perfectly in PowerShell. You use them with identical syntax and all that even if the output is just text and not objects they function just fine. A few applications use syntax that trips up PowerShell – but with the use of the the –% operator, you can continue to use the older syntax (as I describe in a Blog article titled Taming Wild Console Applications in PowerShell v3.

If you are using Windows 8.1, you should know by now that PowerShell is the future (and present!). Get used to it and learn to love it. And please, resist the temptation to go back!

Technorati Tags:

4 comments:

Anonymous said...

Powershell is slow. I could run tens of cmd.exe by the time it's fully loaded. Given that the my most frequently used console command is ping, Powershell loses.

mattypenny said...

I read the title of the original post the wrong way around. I read it as being about replacing cmd with Powershell - a much better idea :)

Although I should say - I do use vi (actually gvim with Powershell syntax highlighting enabled) rather than Notepad...

Thomas Lee said...
This comment has been removed by the author.
Thomas Lee said...

[re-added with hopefully fewer typos]

Depending on what version of PowerShell you use this may be an easy thing to fix (just use Ngen to move PowerShell to the GAC). It might also be due to things in your profile.

My version of PowerShell starts up on my main workstation in just under 4 seconds. That includes creating 8 PS drives, running all 4 profiles, loading a couple of modules, defining then using a couple of functions. By comparison, Cmd starts up in under a second.

So yes, there is a start-up difference. But you could probably not run 10 versions of cmd in the time it takes to start up. And even if you did, what then?

Once you start Cmd up, what do you have - just about everything requires you to start extra processes (i.e. run this command, run that command). Each of which take more time to start up than it takes to load and execute a cmdlet. You also have no direct access to the .NET framework, or all the thousands of task focused cmdlets and of course there's no pipeline. Don't forget there's the performance advantages of compiling functions - which doesn't happen with cmd.exe.

My analogy here: it took longer to start up Concorde than it did to start my Piper Arrow. And yes, I have sat in the cockpit, for real, of several Concorde trips and have .3 of an hour of left hand seat time n my log book. I also had a part share of a Piper Arrow (G-BNEE). My analogy is this: once you start up a Concorde, it would get you to where you wanted to go very, very quickly. Cmd just didn't have the speed or the legs.

Bottom line: if you lean PowerShell, you will quickly find it's power vastly exceeds what you can do with CMD.Exe.

So I concede raw start-up time is faster. And I concede that there is at least one built-in command in CMD.EXE that is not in PowerShell. But once you move beyond the fairly trivial and very exceptional edge cases, PowerShell is SO much more powerful than CMD will ever be.