Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this function coming from <a href="http://powershell.com/cs/" rel="nofollow">PowerShell.com</a> PowerTip it illustrate the usage of <code>Invoke-Expression</code>.</p> <pre><code>function Call { $command = $Args -join " " $command += " 2&gt;&amp;1" $result = Invoke-Expression($command) $result | %{$e=""}{ if( $_.WriteErrorStream ) {$e += $_ } else {$_} }{Write-Warning $e} } </code></pre> <p>That gives :</p> <pre><code>cd "${env:ProgramFiles(x86)}\Microsoft Visual Studio 10.0\Common7\IDE" call .\devenv.exe /command "`"File.BatchNewTeamProject C:\stuff\Project51.xml`" </code></pre> <p>--- Edit ---</p> <p>There are many things to say here. </p> <p><strong>First</strong> you can find a good help with "about" files try :</p> <p>Get-help about-*</p> <p>On the subject you are interested you've got:</p> <pre><code>Get-help about_Quoting_Rules Get-Help about_Special_Characters Get-Help about_Escape_Characters Get-Help about_Parameters </code></pre> <p><strong>Second</strong> <code>CD, DIR, MD</code> works, but they are just aliases on CmdLets which takes different arguments.</p> <p><strong>Third</strong> to get environment variable it's no longer <code>%systemroot%</code> it's <code>$env:systemroot</code>.</p> <p><strong>Fourth</strong> to start an executable file from powershell you can just type the name of the exe :</p> <pre><code>PS&gt; notepad c:\temp\test.txt </code></pre> <p>The command line is first interpreted by powerShell so now if you write :</p> <pre><code>PS&gt; "C:\Windows\System32\notepad.exe" C:\Windows\System32\notepad.exe </code></pre> <p>It just interpret it as a string. So you can use the &amp; operator and write </p> <pre><code>PS&gt; &amp; "C:\Windows\System32\notepad.exe" c:\test.txt </code></pre> <p>It works but :</p> <pre><code>PS&gt; $a = "C:\Windows\System32\notepad.exe c:\test.txt" PS&gt; &amp; $a </code></pre> <p>Fails and </p> <pre><code>PS&gt; $a = "C:\Windows\System32\notepad.exe c:\test.txt" PS&gt; Invoke-Expression $a </code></pre> <p>Works</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload