Powershell is the ultimate Windows scripting language and can run an application from the command line. Have you heard of Unix scripting? PowerShell is a more powerful tool if you are familiar with the Windows command line or MS-DOS.
For a proper introduction, please visit PowerShell on Wikipedia.
Run application from the command line using Powershell
Running an application within PowerShell requires using the ampersand (&) symbol.
1 | & 'c:\somewhere\app.exe' |
When we run the PowerShell command, it will start up the Calculator application. Consider the following images. The command-line window from which we started the Calculator application using PowerShell is on the right.
Meanwhile, on the left, we can see the Calculator pops up.
Passing arguments to an application using PowerShell
Many applications have options that dictate how they operate on runtime. Moreover, programs may have several parameters they need to perform their tasks, and PowerShell, we can provide these parameters as arguments. For instance, consider the case for Java.
Running an application with an argument is similar to invoking an application in a command-line window in Windows. Let’s check the current version of our Java within the command-line window but not using PowerShell.
Again, let’s check the current version of our Java in PowerShell.