Is Windows PowerShell as powerful as the terminal of Unix/Linux?

48

23

Is Windows PowerShell as powerful and efficient as Linux' terminal?

People offline tell me, without explaining much, that Windows PowerShell is an attempt to make Unix administrators feel more comfortable using Windows. But I guess, they will be comfortable only if it has (or almost) same efficiency.

kern

Posted 2014-01-26T16:51:49.903

Reputation: 635

Question was closed 2014-01-26T17:55:36.970

1I am a longtime Unix fanboy who prefers Unix to Windows in most respects; however, PowerShell beats bash hands down because one pipes objects having key/value pairs and not pure text. This makes it more similar in design to jQuery than to bash. – Mario – 2014-12-19T17:11:32.960

3That's hard to answer, because there is not THAT Linux shell. There are many shells commonly used on Linux (or generally *nix systems). The most used one is bash, so you may want to ask about that.<br> Also "powerful" is very opinion based. – Kritzefitz – 2014-01-26T17:02:02.270

8People offline tell me ... that Windows Powershell is an attempt to make UNIX administrators feel more comfortable using Windows. Those people have neither used Unix or Powershell. – surfasb – 2014-01-26T17:23:41.980

I'd say that PowerShell is an acknowledgement from some areas of Microsoft that they messed up by not having a powerful shell available. It does not at all copy the style of UNIX however. To know PS, you really do well to understand a bit about how Windows works and how .NET works. – Julian Knight – 2014-01-26T18:08:29.587

BTW, Microsoft did have a BASH shell available that was part of a migration toolkit supposed to help people move from UNIX to Windows Server. – Julian Knight – 2014-01-26T18:09:17.043

Answers

59

Well, your first problem is that you are comparing a shell (PowerShell) to a terminal. In Linux, a terminal is something that sends and receives character-based I/O and is assumed to have an interactive user behind it (in other words, it's the GUI application used to contain a shell). One of the most common shells run within Ubuntu's Terminal is Bash, but there are others.

People offline tell me, without explaining much, that Windows PowerShell is an attempt to make Unix administrators feel more comfortable using Windows.

Really, the correct thing to say is that PowerShell is Windows exposing much of the WMI, COM and .NET object model in an interactive and scriptable command line environment - and that this command line environment continues to borrow many of the concepts - such as pipelines and I/O redirection - from Unix shells, just like the old DOS (2.0 and up) command.com and cmd.exe did. Pipelines work with objects in PowerShell. You can do things like create HTML and possibly Excel spreadsheets on the fly if you knew enough. It's certainly an upgrade/replacement from the old cmd.exe shell which hasn't changed much from Windows NT 4.0.

Regarding the syntax, it's less like the Unix shells (although finally none of the cmdlets use / as a switch or parameter indicator), but there are many aliases to classic Unix commands - such as entering ls in a PowerShell window will work like dir. But these are just aliases ("Get-Alias" lists these?).

Regarding the capability of PowerShell, you really had similar capability, in a scripted-only fashion, from VBScript and CScript - though both of these predate .NET.

One thing Unix people do not have to do when using Bash most of the time is to be intimately familiar with a programmer's or object's possibly very elaborate object model, which is required for many advanced and simple PowerShell tasks. But this is only possible because there is a clear convention of straight text output for many standard POSIX commands. Windows has not had this tradition - it has seemed to prefer you use an mmc console for adminstration tasks, with commands added here and there over the years. Furthermore, many well-known Unix utilities are complex and require some study before use - rsync, wget, and many others. Efficiency is probably a function of how well one knows the tool they are using more than anything else.

LawrenceC

Posted 2014-01-26T16:51:49.903

Reputation: 63 487

3+1 for mentioning that a terminal contains a shell. I've used Windows and Linux for a long time but never had anyone state the difference so clearly. – Tyler Collier – 2014-09-08T21:23:31.320

8+1 for mentioning that PowerShell exposes .NET to the console & as a scripting host. It exposes the power of many key Windows libraries to be used in scripting. The use cases between the two may be similar, the style is totally different. – Julian Knight – 2014-01-26T18:06:20.437

26

Windows PowerShell and Unix shell are two different things with advantages in both.

Unix (shell) has a philosophy that everything is a file. The input and output of a Unix command can be accessed like a file. This makes chaining command really simple and reusing the output of one command by another is the power of the Unix shell.

With Windows PowerShell, as far as I know, everything is an object. You can pass the result of a command to another as an object. This can be really powerful, but it does not have the simple concept of Unix.

I don't believe that PowerShell is as efficient as a Unix shell, but others believe that it is.

But the comparison is moot, because Windows is not a *nix system, thus *nix concepts don't apply. Compared to MS-DOS, PowerShell is a great improvement.

Biapy

Posted 2014-01-26T16:51:49.903

Reputation: 959

1People keep talking about these objects in powershell. Being used to cmd.exe and bash (or other shells) only, can you elaborate, perhaps with a simple example? – Luc – 2014-10-31T11:04:30.233

@Luc: Here's a good example: https://technet.microsoft.com/en-us/library/ee176828.aspx - $_.name is an object property if I'm not mistaken.

– LawrenceC – 2015-07-22T18:15:00.340

6Without sending you away from this page - when you pipeline things in *nix systems on the right side of the pipe you expect simple text, for example --- history | grep cp --- will return only lines that contain cp. On the other hand when pipelining things in PS on the right side you get an object, with properties, like this --- Get-History | Where-Object {$.CommandLine -eq "cp"} --- $ is each object, CommandLine is the property, -eq is equal to and finally the string cp. – Unknown – 2016-10-31T20:09:23.430

4The everything is a file has nothing to do with the shell, it is a kernel thing. – terdon – 2014-01-26T17:31:19.803

3True, but it impacts on how the unix shell is designed. – Biapy – 2014-01-26T17:38:23.937

@terdon: That's right, but the shell works nicely with this. Because it's still the shell that recognizes symbols like |, < or >. – Kritzefitz – 2014-01-26T17:39:06.253