# How to start any program using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

If you have noticed, you can start notepad and calculator or other standard system utilities with the Windows Run or through the PowerShell console directly by typing just their names, but not the wordpad.exe, word, excel or any other application. It will throw an exception.

For example, just type notepad.exe in PowerShell console and it will open the program but type wordpad.exe there will be an error.

wordpad.exe − The term 'wordpad.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At line:1 char:1
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (wordpad.exe:String) [],
CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

This is because all the programs run through the command whose paths have stored into an environmental variable.

To check the environmental path variables, use the below command.

$env:Path -split ';' ## Output C:\Program Files (x86)\Intel\iCLS Client\ C:\Program Files\Intel\iCLS Client\ C:\WINDOWS\system32 C:\WINDOWS C:\WINDOWS\System32\Wbem C:\WINDOWS\System32\WindowsPowerShell\v1.0\ C:\Program Files\Intel\Intel(R) Management Engine Components\DAL C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL C:\Program Files\Intel\Intel(R) Management Engine Components\IPT C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT C:\Program Files (x86)\Skype\Phone\ C:\Program Files\Intel\WiFi\bin\ C:\Program Files\Common Files\Intel\WirelessCommon\ Programs located under the above path will run directly through the PowerShell console without providing the full path of the application or utility. Now, to open the Wordpad you need to give the full path of the Wordpad. But when you give full path in the double or single quotation it will consider it as a string and returns the same value without executing the program. "C:\Program Files\Windows NT\Accessories\wordpad.exe" To execute the program, you need to use the ampersand (&) sign followed by the full path of the program. & 'C:\Program Files\Windows NT\Accessories\wordpad.exe' Another way to execute the program is to browse to that directory and run the program. cd 'C:\Program Files\Windows NT\Accessories\' and run the program name. PS C:\Program Files\Windows NT\Accessories> .\wordpad.exe So far, we have executed the program with the full pathname. Now we want to execute wordpad.exe, directly from the PowerShell console. To do so, we need to provide the program path to the environmental variable. $env:Path += ";C:\Program Files\Windows NT\Accessories\"

Now you just need to type wordpad.exe from the PowerShell console and the program will open.

Please Note − Change in the environment variable is temporary. Once you close the PowerShell console, the newly added environment variable path will be removed. To add this path permanently you need to use the profile script path and it loads every time when PowerShell console starts.

Published on 14-Feb-2020 07:13:21