September 30th, 2015

PowerTip: Launch Console Command Embedded in Powershell Variable

Doctor Scripto
Scripter

Summary: Use a variable to launch a Windows PowerShell cmdlet and maintain the value of $LastExitCode.

Hey, Scripting Guy! Question How can I use Windows PowerShell to launch a variable that contains the path to a console application
           while retaining the error code?

Hey, Scripting Guy! Answer Use the & character before the content in question. This example launches Tree.com in System32 
           by passing in the Environment variable for Windows:

& "$ENV:Windir\system32\tree.com"

  

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback