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 it has to be adapted to everyone’s needs to be useful.
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 the most advanced users of Windows who want more control over Microsoft software.
However, there are some important differences between the two applications. In this case we want to focus on a specific operating mode, we refer to the possibility of executing .CMD files directly from a window of PowerShell.
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 they contain 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 the batch execution of various commands through a command prompt window. We access it precisely by writing the CMD command in the Windows search box.
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 symbol of the system. 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 to promote 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 simplest way to be able to run a file of these characteristics that we comment, 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, right-clicking on the start menu. Among the many options that we find in this list, we see a called Windows PowerShell.
Another method that will be very useful when executing this functionality is to write your name in the search box of the OS. 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.
Once we have accessed this section using either of the two exposed methods, we find the corresponding PowerShell window.
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 it is not carried out in the same way. Hence, when trying to run 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 run a .cmd file in PowerShell using the Invoke-Expression parameter. This takes care of running 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 run scripts instead of programs, or integrate Invoke-Expression in scripts created in PowerShell to run 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 execute the softzone.cmd file that is located in the system unit E. 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.