How is Powershell Different from Command Prompt? (2021)
For many of experienced IT professionals the question seems a little absurd. Powershell and command prompt share a few similarities, but the differences between the two are vast. We want to expand on this a little and show where you would use each of these tools in your day to day work, or play. We will be looking at Powershell 5.1 in our blog post as it is more closely aligned with Windows processes. Newer versions of Powershell are being developed with the idea of creating a universal platform that can be run on other platforms like Linux. We will be looking more at Powershell 7.2 (and beyond!) in the coming months, so keep checking in with us.
If you are new to Information Technology then you might not really have much of a grounding with using The Microsoft Windows Command Line (CMD). Back in the old days, most administrative work and technical maintenance was done exclusively with text based tools and very few graphical tools existed that would help with getting critical work done. Old DOS based systems used batch files to help automate some scripts and queue up commands and it even had some variable controls as well.
It could not really compete with Linux and Unix systems that had Bash. Many ‘nix system admins were able to harness the power of these systems and were able to build scheduled scripts that were automated and able to interact across sessions and networks. Powershell is the newest of these examples, and it takes things to a new level.
We want to take a step back and look at CMD and Powershell, and how Powershell differs from CMD.
Command Prompt: A Short Backgound
You may have heard a few terms being thrown around like DOS (Directory Operating System), CLI (Command Line Interface), or CMD (Command Line). All of these terms more or less refer to the same thing: a non-graphical interface where users can enter text commands. Text commands can be used to launch built in utilities within the Windows operating system, or they can be used to launch applications.
In a time before 3D accelerated graphics cards and blisteringly fast processors there weren’t too many user friendly operating systems for folks to use. Unix was the king of university computer labs and any other computer required that you understood how to operate them, usually with a big fat user manual close at hand with a list of commands. When DOS first arrived on the scene it made things a lot more simple for people to start using personal computers, and it helped to create demand for the fledgling personal computer market.
Most people had no use for a mouse, and only needed a keyboard to get around the operating system. Eventually as computers moved on to bigger and better things like Microsoft Windows, development of the command prompt started to take a back seat. That is not to say that things were not still maintained and updated, but the consumer focus was understandably on the Graphical User Interface of Windows. Even the time honored traditions of creating and executing bat files could be accomplished by using notepad and then executing creations from the desktop with a simple double click. Command prompt didn’t even have text completion in the early days, so typing out the full paths to directories got really old really fast.
CMD in its current iteration is used primarily as a diagnostics tool to help and repair Windows installations that cannot boot into the main OS. You are normally guided towards this as a repair Windows screen and it can be found under advanced options.
By going into the command prompt you can run useful tools like diskpart to check out your current disks, chkdsk to scan the health of your file structure and drives, and sfc to rebuild indexes and other important files on our hard drive. There are many other things you can do from here as well, such as copying over backups of important system files and configs so that you can restore a computer to a bootable condition.
Powershell: A Little History
Powershell was the brainchild of Jeffery Snover back in 2003. There is quite an interesting backstory, including a famous manifesto for the then named Monad (Powershell has a much better ring to it, don’t you think?)
From the beginning, Powershell was designed to be an automation tool with .Net at its center. Taken from the Monad Manifesto:
“Monad is the next generation platform for administrative automation. Monad solves traditional management problems by leveraging the .Net Platform. From our prototype (though limited), we can project significant benefits to developers, testers, power users, and administrators. Monad leverages the .NET Common Runtime to provide a powerful, consistent, intuitive, extensible and useful set of tools that drive down costs of administration and make the life of non-programmers a lot easier.”
I really appreciate the last few words of that quote “…make the lives of non-programmers a lot easier.” because a few years ago I was a non-programmer, struggling to solve problems at work. When I first came across Powershell, I was able to sit down and write a script in a single afternoon. The script was very simple – it restarted a process that would fail from time to time due to a memory leak- usually in the middle of the night- causing the factory to to stop production.
When its memory use was getting out of control I would have my script restart the service, which would then start behaving itself again for a few days, weeks, or sometimes months. (I received an email every time it had to smack the process back to its senses).
The process in question controlled the main PLCs on the floor, which operated the instruments attached to the manufacturing plant. This was an issue that the vendors and suppliers couldn’t solve cheaply, and they wanted us to spend huge amounts of money to upgrade to their latest and greatest solution. Needless to say the bosses were very happy – and my little script is probably still running to this day. I no longer work there, but it piqued my interest and got me on the road to learning how to code.
What Are the Main Differences Between CMD and Powershell?
Powershell was designed to be a Bash-styled command line tool that integrated tightly with Windows .NET frameworks. It is a powerful tool that has been actively developed, updated and improved over many years – so it is not really a question about whether it is better than CMD or not. It is simply an evolution of command line tools, and it is obviously better at everything than CMD is. Instead, we are looking at what the differences are between the two.
Powershell is a far more interactive tool which makes it ideal for creating scripts and fully interactive applications. You can even compile Powershell scripts into exes and install them as services on your server, computer or laptop. This makes it a very different creature to what CMD is. And that is not to knock CMD. On the contrary, CMD has all of the raw utilities and basic functionality that is needed in order to accomplish simple tasks. This is even more true when you are trying to bring a system back from the brink of an Operating System failure, or boot issue. So with this in mind, we have decided to wrangle a list of some of the most common commands that are used in CMD, and we have paired them off with similar Powershell cmdlets. Below is a table that we have put together that distills the main differences that we come across in our daily work, and general alternatives between CMD and Powershell.
Uses cmdlets, scripts and executables
Uses executables and batch files
Libraries of modules for added functionality
Uses applications and executables
Full Programming Language
Command Line Interpreter
Global, Script, Session and Cache scopes
Global and Local scopes
Object Oriented output
Getting Things Done: cmdlets, scripts, executables and batch files
Powershell uses a range of and combination cmdlets (command-lets) that are both native to Powershell and installed via third parties and Microsoft’s own Powershell Gallery. Powershell has a range of different cmdlets that do exactly what CMD commands can do. Below are some examples of the commands that CMD does, and the equivalents that are found in Powershell.
Create Directory (and files for PS)
Set-Location: Set-Location is Powershell’s way of navigating or setting a location in a script. You can use this to target a location or you can use it to navigate around the environment with it. It replaces the tried and test cd command. (cd stands for Change Directory)
CMD Example: cd\exampledirectory Powershell Example: set-location -Path "c:\exampledirectory"
Get-ChildItem: Get-ChildItem is Powershell’s cmdlet that allows it to read data about objects such as files and directories, much like CMD’s dir command. Get-ChildItem has a lot more functionality than simply listing the contents of a directory, so it is definitely worth reading the documentation that we have linked above.
CMD Example: dir c:\exampledirectory Powershell Example: get-childitem -path c:\exampledirectory
Rename-Item: Rename-Item allows users to perform the same operation as CMD’s ren command. It is far more simple to use a mouse to do this, and it is probably the more commonly used method of renaming files but being able to do this with text commands is important.
CMD Example: ren c:\exampledirectory\examplefileold.txt c:\exampledirectory\examplefilenew.txt Powershell Example: rename-item -path "c:\exampledirectory\examplefileold.txt" -newname "examplefilenew.txt"
Get-Help: Everybody gets stuck sometimes, and when that happens we ask for help. Before the internet and search engines, users needed help finding out how commands would run by following a command with /? . In Powershell this is done by typing get-help followed by the command that you need help with.
CMD Example: dir/? Powershell Example: get-help get-childitem | out-host -paging
Remove-Item: When it comes time to send things into the void of nothingness, CMD users have the del command. There are plenty of command switches that can give you increased functionality with it. Powershell uses the remove-item command as a replacement for that same purpose, and it also has as huge amount of additional functionality just by virtue of the fact that it is a Powershell cmdlet!
CMD Example: del TestItem.txt Powershell Example: remove-item TestItem.txt
Copy-Item: Copying files across your hard drive and network is really important, so both CMD’s copy command and Powershell’s copy-item command will get a quick run down as well. Copying files in Powershell scripts is also possible with this command. Most people use xcopy in bat file scripts, or third party copying apps, but we are just looking at plain old copy.
CMD Example: copy c:\exampledirectory1\test.txt c:\exampledirectory2 Powershell Example: copy-item "c:\exampledirectory1\test.txt" -destination "c:\exampledirectory2"
New-Item: If you have ever wanted to create a folder when in the CMD prompt then you might be familiar with the md command, which stands for make directory. Powershell has its own version of this, although it allows you to create more than just folders. You can create files, credentials, and even profiles with new-item, but we will be looking at the directory or folder creation capabilities of these cmdlets/commands.
CMD Example: md testdirectory Powershell Example: New-Item -Path "c:\" -Name "testdirectory" -ItemType "directory"
Conclusion: So What Are the Differences?
As you can see there are tons of differences between CMD and Powershell. And this is not to say anything negative about CMD – it has been used for a very long time and it has served an important purpose in the Microsoft Windows ecosystem of Operating Systems. Unfortunately is was never designed to scale with modern computer networks and systems, and much of its core commands and features were ported from previous versions of MS-DOS, at least in a very loose sense.
Powershell is a necessary tool if you are administering computers on a network, servers in a cloud, or scripts in a department. There are a ton of reasons to learn Powershell and get a feel for what you can do with it. Once you have found a challenge or solution that you think is worth investigating then why not look into finding out how to build your own solution. You might surprise yourself to find that you are not only capable of solving issues on your network, but learning new and advanced skills at the same time. This can lead you on a path to learning Python, C# or anything else that uses the same object oriented principles that we find in Powershell.
We hope that you have found this article useful, and hopefully you have learned a thing or two about what the differences are between Powershell and CMD. What are some of your favorite cmdlets that you use often as as replacement for the CMD equivalents? Did we miss any important ones? Let us know in the comments and we will do our best to include them.
Cheers until next time.