9 Differences Between Powershell And Windows Command Propmt
windows command prompt and blue command prompt also known as Powershell. Powershell vs cmd, what are the differences? well, they’re both share the same idea but what’s the point of having two same programs on your Computer? The very short answer is, although they are used for the same purpose, PowerShell is just more advanced and more powerful than cmd. By the way, cmd and command prompt refers to the same.
Though, the answer is stated forward still we understand the difference between these two programs and why you might want to use PowerShell over command prompt. Should you even bother learning Powershell? Well, there are a lot of advantages in PowerShell actually and it is way more powerful.
Command Shell Overview
First let’s actually just take a look at what microsoft itself says is the difference between Powershell vs cmd.
Now don’t worry if you don’t understand a lot of that. You don’t know what the heck is cmdlets. I’m going to get into that later in this article and make it easy to understand. Basically, the only thing you need to understand at this point is that PowerShell can do pretty much everything the command prompt can do. It can run pretty much all the commands the cmd can run. But PowerShell can do some extra more things.
If you’re familiar with both then there’s really no reason to not just use PowerShell for everything because it can do everything with the same commands as cmd can. But of course, if you’re familiar with only the command prompt then you’re not going to be using anything in PowerShell, may be worth it to learn some PowerShell commands.
Powershell Is A Scripting Language
Another very important thing you need to know is that Powershell does not just refer to the PowerShell program that you run in windows. It is referred to as an actual scripting programming language also called Powershell.
Whereas the command prompt or cmd pretty much just an old legacy environment for dos commands just for backward compatibility. It is still here just because a lot of people still used it and more familiar with it. But command prompt is extremely limited.
You see with the command prompt you type a command, it runs the command and that’s pretty much all.
Whereas with Powershell, because it’s an entire language and the PowerShell program supports the PowerShell scripting language, you can actually able to do so much extra stuff as you do with a programming language right in the PowerShell window.
So you for example could set variables, create a function to do all this right through the PowerShell window. Which is not something you can do with the command prompt. You just basically type in commands in the command prompt.
Whereas with powershell you could do all sorts of different weird stuff and just right through that window.
Read more: Gaming PC Build Under 50000 Rs In India 2020
Powershell Has “cmdlets”
Now I mentioned before that PowerShell is more powerful than command prompt but what do I mean by that? So both command prompt and PowerShell are capable of taking control over the operating system, changing settings that sort of thing.
But PowerShell can do just way more settings than the command prompt. And like I said because command prompt is just a legacy environment. Powershell is what Microsoft has been working on since Windows 7 as the main command shell to be used for everything.
So anytime they add a new setting that they want to be changed by a command shell it’s obviously going to be used in PowerShell. So it can do way more, whereas the command prompt just gets more outdated by the day.
Now both command prompt and powershell have just basic commands like showing a directory or changing directory, super basic stuff for interacting with the shell, deleting files etc.
But the difference is Powershell also has these “cmdlets”, which are more advanced functions created by microsoft and then put in into Powershell.
It might seem intimidating at first because the commands in Powershell are all different from the command prompt. But that’s not exactly the case because they basically created “Alias” which makes the old commands do the same thing as the new commands.
Powershell Support “Alias”
All the commands in Powershell from my understanding have a certain structure. So it’s a verb-noun structure. For example “Set-Location”, it’s a verb and then a noun. And all the commands are going to look like this.
However, that doesn’t necessarily mean that if you’re already familiar with the command prompt or even the Linux bash, that you have to learn all of these new commands and memorize them just to be able to use PowerShell.
With the support of “Alias” which basically just a link that says, okay if someone types in “cd” for change directory in the command prompt, that is going to link to the set location command in Powershell. “cd = Set-Location”.
It’ll do the exact same thing. So pretty much all of the old command prompt commands do the exact same thing in PowerShell. You don’t have to learn the new Powershell command at all.
And another really important thing to remember is that a lot of these command prompt commands you’re probably familiar with are might not even be commands at all.
A lot of them are not commands but rather programs in the system 32 folders in windows. For example, when you run the ping command, it’s not exactly a command. You’re actually running “ping.exe” that’s in the system 32 folders.
For other common programs like “chkdsk“, “ipconfig” and more. These are all actual “.exe” programs in the system 32 folders that you’re running. They’re not just exclusive commands to command prompt. So if you type these commands into the Powershell it’ll do the same exact thing.
Getting More Info About Commands
You can even see this when you look up the info in Powershell about each individual command. So you can actually use “Get-Command” as a command to look up another command. It’ll tell you info about it.
So if you type “Get-Command ping” it says command type is an application and it points to “ping.exe”. Another example for an “alias“, if you type “Get-Command cd” you get information about this command.
If you want to see them all you can just type “Get-Alias” and see all the aliases that exist. But if you do this you’ll probably notice that not all of these aliases are command prompt commands, some of them are actually Linux bash commands.
So yes if you’re familiar with the Linux bash command already then you again do not have to learn any of these new commands you can just use the alias for the existing bash command that you’re already familiar with and it’ll do the same exact thing.
For example the “ls” command which lists directory contents that also is an alias for the “Get-ChildItem”.
Pipe System In Powershell Makes Life Easier
Now I already mentioned how there are a lot more functions and stuff that Powershell can do. But also how you actually work with these commands in Powershell is a lot easier and different than in command prompt.
That’s because powershell uses what are called pipes to pipe data from one command into the other and let me explain what that even means.
So with a command prompt you probably know you basically just type in a command, it’s all text, as a string of text and then the command prompt will output a bunch of text as the output. And if you want to use that output from a command prompt command, as it’s just a string of text you either have to copy it and then put it into a new command separately.
But with powershell you can actually take the output from one command and pipe it directly into the input of another command.
That’s because instead of Powershell getting outputs in the form of just a string of text that you have to basically parse out or separate out and get the exact amount, Powershell actually can output results in an “object”.
Powershell Creates Object As Output
So, what is an object? Instead of it being a long string of all the text, the data is separated out into chunks that are kind of label in a way behind the scenes that the programming language can interpret and much easier get out the data exactly what it needs.
So the consequence of this like I mentioned, is that Powershell can take that object or organized information from the output of one command and put it directly into another command.
Without having to do any other extra work and the new command will automatically know how to take the part of the original output that is needed for this new command. And it can just ignore whatever else it doesn’t need.
Whereas you would have to specifically pick out the information if it was just a string output like command prompt. So it’s way easier to do a much more complex series of commands with Powershell if you need to.
Now let’s talk about scripts though. Because I also mentioned that Powershell is also the name of the scripting language of the same program. But the command prompt also is able to do scripts using what are called batch files.
Powershell uses “ps1” files as the script extension. And there should be no surprise here that batch files are way more limited than powershell scripts.
For example, in batch scripts, you can’t even use “nested if statements”. It can only be one “if statement” at a time and if you want it to be another one you have to use the “Goto” command.
So you have all these random parts of code at different points in the file and then you have to go to each one and it ends up just being spaghetti code bouncing all over the place, hard to figure out what’s going on, it’s a pain.
Whereas In Powershell as it’s a scripting language you have nearly all the features a programming language has. So the Powershell script ended up being a lot more organized and will be a lot easier to modify in the future.
There are also some other oddities that you’ll probably have to get used to. For example, if you want to run a “.exe” file from the Powershell program, you can’t just type the name of the “exe” file like you can a command prompt.
Even if you’re in the same directory you have to type “./” to show that you want to use the current directory and then the “exe” file. Because for some reason Powershell doesn’t assume that you want to run the file in the current directory it’s in. So that’s just one thing you have to keep in mind.
So overall if you’re just using the most bare-bones basic commands in cmd and that is all you’ll ever use, I mean yeah you can just use command prompt and not miss anything in PowerShell.
But I would still suggest at least getting a little bit familiar with Powershell so that you might realize in the future that there is something you can do with Powershell that you never would have thought was even possible in command prompt. So then you’ll at least know, and then you can keep using the same commands in Powershell anyway.