Running Windows Programs

Updated: August 29, 2012

Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0

You can run Windows command-line programs and start Windows graphic programs by using Windows PowerShell commands. If the program generates text output, you can capture the text and use it in Windows PowerShell.

You can run many programs just by typing the program name. For example, you can start the Notepad program by using the following command.

PS> Notepad

This command works because the executable file for the Notepad program is in a location that is listed in the Path environment variable.

To start programs in other locations, type the full path to the program. If the path includes spaces, enclose the path in quotation marks and parentheses and use the call operator (&) to run the quoted string.

For example, the following command starts Microsoft Word.

& ("C:\Program Files (x86)\Microsoft Office\Office14\Winword.exe")

To make this command easier to run, create a function and save it in your Windows PowerShell profile. For example, the following command creates the Word function.

function Word 
{ 
    & ("C:\Program Files (x86)\Microsoft Office\Office14\Winword.exe") 
}

Now, to start Microsoft Word, just type Word.

When running a program, you can include program parameters and parameter values or arguments in your command.

For example, you can run a Net command that adds a member to the Administrators group on the computer.

PS> net localgroup Administrators /add Domain01\User01

"Net" is the name of the program. The remainder of the command consists of parameters and their arguments.

Occasionally, Windows PowerShell misinterprets program parameters, arguments, or syntax symbols as Windows PowerShell commands or expressions.

For example, the following Icacls command generates errors in Windows PowerShell.

icacls X:\VMS /grant Dom\HVAdmin:(CI)(OI)F

Beginning in Windows PowerShell 3.0, you can use the stop-parsing symbol (--%) to tell Windows PowerShell not to interpret the characters that follow it on the line as Windows PowerShell expressions.

icacls X:\VMS --% /grant Dom\HVAdmin:(CI)(OI)F

When Windows PowerShell encounters the stop-parsing symbol, it doesn't do any interpretation, other than replacing environment variables in Windows syntax (%<Name>%) with their values.

As a result, Windows PowerShell sends the following characters to the Icacls program.

X:\VMS /grant Dom\HVAdmin:(CI)(OI)F

In Windows PowerShell 2.0, you can achieve a similar effect with just a bit more work. Use the Windows PowerShell escape character (a backtick or grave accent character (`)), to escape the parentheses in the command, as shown in the following example.

X:\VMS /grant Dom\HVAdmin:`(CI`)`(OI`)F

For more information about the stop-parsing symbol, see about_Parsing. For more information about escape characters, see about_Escape_Characters. For more information about environment variables, see about_Environment_Variables.