Powershell

PowerShell Start-Process

You may have tried to open many applications of files within your system in one or two ways. The PowerShell Start-Process is the very well-known command to quickly launch one or more files, applications, or processes in a very organized way. It is a quick start of some application programs to avoid wasting time. It can make executable files run. You can make use of the cmdlet Start-Process command by utilizing different usernames. Within this tutorial guide, we will see how to use the Start-Process cmdlet in PowerShell. So, make sure to have a PowerShell utility installed on your Ubuntu 20.04 Linux terminal. Open the terminal via “Ctrl+Alt+T”, and start the PowerShell by using the command shown below, i.e., pwsh.

Example 1

Now the PowerShell has been started properly, move on to some examples. If you don’t have any text files in your Ubuntu 20.04 system, then make one. Make sure to create it within the home directory of your Linux system to access it quickly. After the creation of a file, add some lines of data into it. We have named the file “new.txt”. As we know that, the Start-Process cmdlet is used to open any executable and normal file quickly. So, let’s use it in our PowerShell to open the newly created file, i.e., new.txt in our default text editor of the Ubuntu 20.04 system. So, we have tried the command shown in the image followed by the name of a file. In return, it doesn’t display anything on the PowerShell screen for a second.

After 2 and a half seconds, the file new.txt will be quickly opened in the default text editor of the Ubuntu 20.04 system. The output would be something like shown in the image below. The opened file shows a total of 10 records for echo statements in it.

Example 2

Let’s have a look at some parametric attributes within the “Start-Process” command. So, one of the attributes is the “pass-thru” parameter used to get the information regarding the particular process related to the specified file, i.e., text or executable. So, we have utilized the Start-Process cmdlet within the PowerShell followed by the name of a file new.txt and parameter, “pass-thru”. This parameter gets all the required information of a file new.txt after opening it via the Start-Process command and saving the information within the variable “v”.

After a while, the new.txt file will be opened in a default text editor of the Ubuntu 20.04 system. The launched text file in an editor has been displayed beneath.

Example 3

We can use the variable “v” to get the process ID of a particular file, i.e., new.txt. So we did it using the variable “v” along with the keyword “id” and dot. It returns us the process ID for this file which is 6039 in our case as per the output shown. You can also use the variable “v” to stop the process 6039 as you are aware of it now.

Example 4

Another well-known attribute used along with the “Start-Process” cmdlet is “Confirm”. It is quite simple to use in the code and quite beneficial. It is a checkpoint before directly running some file or folder to avoid inconvenience. Upon executing the Start-Process command and filename “new.txt” and parameter Confirm, it returns us some of the targeted options, i.e., Yes, No, Yes to All, No to All, Suspend, and Help. When a user adds any of the options shown below on the PowerShell, it will do accordingly.

Upon using “[Y]Yes”, and “[A]Yes to All option will quickly open the text file. While all the other options will suspend the processing.

Windows 10 PowerShell:

Let’s have a look at one or more examples of using the Start-Process command within the PowerShell of Windows 10. So, start the PowerShell of Windows 10 by searching it in the application area. Run it by tapping on it, and you will get a blue application opened on your screen. Let’s use the “Start-Process” command to open the PowerShell with sudo rights. To do so, add the parameter “Verb” and specify the value “RunAs” after it. Execute the command shown in the attached image below and wait for a while to see the output.

As a result, it would open the PowerShell with sudo rights as per the image attached below. You can make use of any command on this privileged PowerShell.

This is how a PowerShell can be opened with the Start-Process command. Let’s open the notepad application in our Windows 10 using the same Start-Process instruction. So, we have utilized the Start-Process cmd command in the PowerShell to open the notepad.exe file. Pressed the Enter key to execute the file shown in the image.

It quickly opened the notepad and a new file on our screen. Close it to move on next.

You can also use the parameter “FilePath” and add the file path wherever required. Most of the time, it is required where the location of a file is a little far from the home folder.

Upon executing this updated above command, I have got the new notepad file opened on my screen, as shown below.

We have been using many attributes within this command this time. The “WindowStyle” attribute has been used to specify the window style of the notepad in which it will be launched on the screen. We have specified its value as “Maximized”. This means the notepad application will be opened on your screen quickly in front of any screen you are currently on.

After executing the above command, we have got the maximized window of the notepad on our screen front.

Conclusion

This guide contains the use of the Start-Process command-line utility to launch or open any sort of files, i.e., text or executables, in the PowerShell. This guide covers the usage of the Start-Process utility on the Ubuntu 20.04 Linux system and Windows 10 operating system. All the illustrations contain simple and easy ways to start the processes.

About the author

Omar Farooq

Hello Readers, I am Omar and I have been writing technical articles from last decade. You can check out my writing pieces.