Run files in .cmd format from PowerShell

One of the great attractions of Microsoft‘s operating system, Windows, is the graphical interface that we can use. In fact, it is one of the sections that most caught the attention of users who came from MS-DOS- based computers. However, command lovers can still use them thanks to the Command Prompt window and PowerShell.

The Redmond operating system puts at our disposal a huge number of functions and features included by default. At the same time they try to greatly facilitate the work with all this thanks to the aforementioned graphical interface. Keep in mind that the Windows operating system is used by more than one billion people around the world, some with more knowledge than others. Therefore, the software has to be adapted to everyone’s needs to be useful.

Run files in .cmd format from PowerShell

As we say, at the same time, it makes certain functionalities available to the most advanced or experienced users. With these they can get the most out of the operating system and adapt it to their needs. Take the command prompt window or the PowerShell application as an example. Surely many of you already know that these two sections of the system base their operation on the use of commands. Therefore, they are especially aimed at more advanced Windows users who want to have more control over Microsoft software.

However, between the two applications there are some important differences. In this case we want to focus on a specific operating mode, we refer to the possibility of executing .CMD files directly from a PowerShell window.

What is a .CMD file

At this point, the first thing we need to know is really what .CMD files are and their main utility. Well, these are a type of file used on Windows-based PCs. As a general rule, they are used for the batch execution of a series of orders that we put together in said file. In this way, the .CMD contains a series of commands that we expect to be executed when we invoke it.

In addition, these are placed in a specific order, which is precisely in which they must be executed when making the call to the .CMD in one way or another. Therefore, this particular file format is known as the file format for batch command execution. It must be said that on many occasions these files are used for batch execution of various commands through a command prompt window. We access it precisely by typing the CMD command in the Windows search box.

abrir cmd

Over the last few years, a clear substitute for this section has been PowerShell, which is why many users have decided to switch to this other Windows tool. In fact, it is considered a more powerful and versatile application than the command prompt . It offers us many advantages when working from the command line, although at the same time it also has some drawbacks, especially for less experienced users.

Run a .CMD file directly in PowerShell

As we are, the utility encourages files in .CMD format is very high in certain types of use. However, some users may find that they cannot run these files directly in a PowerShell window. Well, if you find yourself in this case that we have explained to you, then we are going to help you. Specifically, we are going to tell you the easiest way to run a file with these characteristics that we are commenting on, directly in PowerShell.

Open a PowerShell window in Windows

It is clear that for this the first thing we have to do is access this functionality of Windows 10 that we are talking about. We have several ways to access this section, for example, by right-clicking on the start menu. Among the many options that we find in this list, we see a called Windows PowerShell.

powershell inicio

Another method that will be very useful when executing this functionality is to write its name in the search box of the operating system . In addition, when we see the corresponding entry to open the application, we recommend that you right-click on it. This will allow us to run it with administrator permissions, which will offer us many advantages, especially for more advanced users.

powershell abrir

Once we have accessed this section using either of the two exposed methods, we find the corresponding PowerShell window.

ventana de PowerShell

Run.CMD from PowerShell window

The first thing to know is that PowerShell works differently than the command prompt window. That is why the execution of certain commands in both applications is not carried out in the same way. Hence, when trying to execute a batch file that we have talked about previously directly, it will show us an error message.

But that does not mean that this is something that we cannot carry out from this tool, but we will have to use an additional command. We tell you all this because we have the possibility of executing a .CMD file in PowerShell using the Invoke-Expression parameter. This takes care of executing the command specified below or any program on the local PC from directly in a PowerShell session.

This is something that we can also use to execute scripts instead of programs, or integrate Invoke-Expression in scripts created in PowerShell to execute programs or files from them. To make you one I will go to the format that we should use here, we will give you an example. Next, we are going to show you how to create how to run the softzone.cmd file that is located on drive E of the system . It is not necessary to explain that previously in this file we have already placed the commands that we want to execute in batches.

Invoke-Expression -Command "E:/softzone.cmd"

In this way, thanks to this simple command that we specify before the file path, a wide range of possibilities opens up in PowerShell. Its subsequent use will depend on the knowledge or experience of each in this type of projects in Windows.