10/01/2023
read 10 minutes

Differences between PowerShell and CMD: what to use in work

/upload/iblock/08d/lgwuyt1il39jex1ga7pxnf7qzeb7oz8v/04TOvIQpyEoEZsqKyJIEBVS_9.fit_lim.size_1600x900.v1577842694_1_.jpg

CMD and PowerShell are both useful software that are used to communicate with the Windows operating system. If you compare the mentioned programs, you will notice their strong similarities, but they have drastic differences. Let's take a look at the main ones.

What is the Windows CLI?

The command-line interpreter (more commonly known as the Windows command line interface) is a command interface that first originated with MS-DOS in the 1980s. It allowed users to interact directly with the operating system.

Such a command interface offers a platform for executing applications and several utilities, with the results presented in the same window. The command line can be utilized to craft and modify scripts, saving them as batch files, for automation purposes within the system.

How to open the CMD?

To start comparing the mentioned software, we should deal with the issue of finding and working them, as many users do not have a proper understanding of these programs.

The command-line interpreter is opened using several methods, and it is pre-installed in every Windows system. The easiest way is to open it using the search bar. To do this, enter cmd into it.

The mentioned method is used by most users as it is considered convenient and efficient, however, there is another way to access cmd.exe:

Simultaneously hold down the win+r keys on the main screen and the run menu will appear. In it you need to specify this command: cmd.

In addition to the above-mentioned options, there is a manual method of opening the CMD. To do this, find the program location and open the corresponding file - C:Windows\Windows\system32\cmd.exe.

To work with the command-line interpreter you need to use commands and specify their parameters, because it simply has no graphic design.

To give an example, if you want to know the status and other data about communication with a remote host, you need to specify this command in the line:

ping -r google.com

The command is "ping", its parameters are "-r", but the address of the remote host is located in - google.com.

By specifying this command, the CMD starts immediate processing of the specified task. In addition to the above command, the CMD can perform many other tasks.

It is worth noting that incorrectly entering the code in the command line can have dire consequences. In the best case, the user will simply learn about the error and the command will have no effect on anything, and in the worst case the task will be executed incorrectly and show an incorrect answer.

If you don't have much knowledge in using the CMD, just specify the command you need, and then you will see the different parameters that can be used.

What is Windows PowerShell

When it comes to PowerShell, we are dealing with an advanced version of CMD. This software can be used on different platforms and is intended to automate various simple processes. By its structure, the mentioned program is a command line shell, as well as a set of languages for creating new scripts and managing old ones.

The difference between this program and the previously discussed command line can be seen from the first minutes of startup. The most basic is the simplification of commands in the PowerShell environment, the so-called cmdlets. This solution simplifies the interaction process, as most of the commands are the same as their actual purpose.

Let's look at the difference more clearly:

  • Task appearance in CMD: ping
  • Task appearance in PowerShell: Test-Connection

In this way, cmdlets greatly simplify control over the operating system infrastructure. At the same time, such a solution provides users with the ability to gain remote access to WMI, or more specifically, to the file system, registry, and space.

When reviewing this software, you should realize that it was released not so long ago. Therefore, its functionality is similar and even more extensive than that of other common shells. It should be noted another feature of the mentioned shell, which is the work with .NET objects. While most of all currently known shells are able to perceive only text.  For an ordinary user, the advantage of this method of work is the absence of the need to parse the text, because the result is already processed and is in the required format.

The PowerShell is used in many areas, but most often it is used to automate the process of controlling systems, as it is suitable for creating difficult tasks with a large number of requirements. In addition to automation, the mentioned shell can be found in the process of testing, building and deploying various programs.

The process of opening this shell is performed in the same way as the CMD. This will require entering the shell name into the search box or through the run menu. On some releases of Windows there is another method of opening, which is the Power User Menu. To open this menu, simply press two keys at the same time - win+x.

Why Would an Average User Need PowerShell?

As mentioned above, the main difference between these shells is usage. When it comes to the CMD, it is suitable for working with batch tasks, as well as for solving not difficult problems. PowerShell, on the other hand, is used during a wide variety of tasks, such as working with batch commands or controlling targets.

Special attention should be paid to working with scripts, which are a plain text document with a few or full sets of commands.

Let's put this feature into practice by creating a simple 1 line script that will output the text.

The first thing we do is to create a script file (ps1 extension), in which we write the following line:

Write-Host “Hello!”

In the PowerShell specifies & and the location of the document we want:

&C:\Users\user\Desktop\script.ps1

How do I get help?

Initially, we need to discuss all the commands, namely what they are. There is no need to use third-party sources for this, as this information is available inside the shell itself.

To do this in CMD, we need to enter the command help in the command line. After entering it, you will see a list of all existing commands.

For PowerShell, a slightly different command is used, namely Get-help. It must also be entered in the command line.

How do I change the directory?

To change a folder, we need to enter command Change Directory (cd) in the command line. It is responsible for switching between directories within the storage of your system.

PowerShell has a similar feature, but it requires a different command, namely Set-Location-Path <folder name>.

In addition to navigating between folders, there is an additional command cd/. It takes you to the root of the file hierarchical structure (directory tree).

To go to the desired directory of your computer enter the above command CD <directory name>. For example, you want to go to the “user” folder, which is located in the C:/users, then type cd users/user.

In addition to changing the directory, it is possible to move to another disk. To do this, you need to specify the name of the disk and put “:”. PowerShell has a similar function, but to move between disks you need to add set-location before the name, e.g. set-location c:.

How to list files in a directory?

If you need to list the documents in a folder using the CMD, use the command dir.

PowerShell has a similar feature, but the command spelling is much different – Get-ChildItem.

How do I rename a file?

It is quite easy to change the name of a document in a certain folder using the CMD. To do this, you will need to specify the command ren. Then enter the original name of the desired document and the final name, for example, ren (oldname) (newname).

Using PowerShell for this task, you can change the name of the document using Rename-Item. It allows you to change the name of folders and files, e.g. C:/Windows\(oldname) (newname).

Key differences between PowerShell commands and CMD

After a theoretical introduction, let's start comparing practical commands. Of course, it is impossible to discuss all available features of each shell in one review, so we will limit ourselves to popular tasks.

  • Ping – is written in the CMD and has a similar command in the Powershell, namely Test-Connection.
  • Tracert – in order to trace the path of information in the public domain and also in the PowerShell, namely Test-NetConnection -TraceRoute.
  • IPConfig – has an alternative in PowerShell Get-NetIPConfiguration.
  • Nslookup – responsible for creating a DNS query. The PowerShell uses a Resolve-DnsName. It provides the ability for users to request names.
  • Netstat – there is a similar command in PowerShell - Get-NetRoute, which allows you to find out about available TCP connections.
  • Route – has an alternative command for the PowerShell – Get-NetRoute. It allows you to get IP path data from the IP routing list.
  • Netsh - is a full-fledged software that is based on the command line. It is used to control and edit the specified network parameters. For the PowerShell there is a similar command that opens in the same way.
  • Gpupdate - has a similar in functionality task in the PowerShell, which is spelled as follows - Invoke-GPUpdate. It is responsible for updating the group policy configuration, including protection settings that reside on remote systems.
  • Gpresult - responsible for receiving and writing RSoP data to documents. It has a similar in action command in the PowerShell – Get-GPResultantSetOfPolicy.

The difference between the CMD command line and Windows PowerShell: what to choose

That's the end of today's comparison of the two command-line interpreters. Of course, PowerShell is superior to the default command interpreter, but many people continue to use more familiar solutions and this is absolutely normal.

However, when solved, the transition will not be a difficult process as PowerShell works with most of the principles found on the CMD. This is made possible by porting most of the old commands to the new environment.

If you want to keep up with progress, the newer PowerShell is the obvious choice. It has a convenient syntax, many features and almost no weaknesses. However, the CMD can perform most of the necessary tasks for today.

News
10 September 202409/10/2024
read 2 minutesread 2 min
Product Digest
30 April 202404/30/2024
read 2 minutesread 2 min
Product digest quarter 1
5 April 202404/05/2024
read 1 minuteread 1 min
Introducing Our New Location in Kazakhstan
Create
3HCloud account
arrow
arrow hover
 
Name*
Phone number
E-mail address*
Please describe your request*
Файл
Файл
Файл
Файл
Файл
Файл
Файл
Файл
Файл
Файл
Form type
ID тикета Zendesk
Product
IP
 

Create a free account now
or contact us to learn more.

By clicking Submit you consent to the processing of your personal data.