Powershell vs CMD

Let’s compare Powershell vs CMD. Both Powershell and CMD are command line interfaces (CLI) or shell environments for WindowsA Computer Operating System made by Microsoft Corporation. CMD is the older version, and Powershell is where Microsoft is now putting all of their develoment resources.

CMD

You can think of the CMD environment as the evolution of Microsoft DOS (Disk Operating System). While CMD might look a lot like DOS, it is not really the same thing. CMD was merely the shell that DOS used. Over the years, CMD has evolved and added commands. But to make any real changes without breaking backwards compatibility, Microsoft needed to create a new shell environment.

Powershell

Powershell version 1.0 was introduced in November of 2006. It uses the concepts of cmdlets and the pipeline to give you a powerful scripting language to accomplish a large array of tasks.

Each command in powershell is called a cmdlet, and the pipeline is how you pass the output from one cmdlet to the input of the next one.

Cmdlets

Cmdlets have a somewhat predictable pattern, and usually have a hyphen in the middle. For example, test-netconnection and out-file. In these examples you have something you are doing, such as a test or an output. Then after the hyphen you have a more specific command where you are testing the network connection or outputting to a file.

Pipeline

Let’s say you wanted to test a network connection, then take the output to the command and write it to a file. This is when then pipeline comes into play.

You could run:

test-netconnection google.com | out-file c:\test.txt

The above command will run a ping test to Google.com using the test-netconnection cmdlet, then pipe the commands into the out-file cmdlet, which will write the results to c:\test.txt

This pipeline functionality is not new in powershell. There was some of it in CMD as well. However, almost every cmdlet has pipeline functionality in powershell. Whereas only a few commands can really take advantage of it via CMD. For example the findstr.exe command.