<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Invoking a PowerShell script from cmd.exe (or Start &#124; Run)</title>
	<atom:link href="http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/feed/" rel="self" type="application/rss+xml" />
	<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/</link>
	<description>Totally addicted to PowerShell</description>
	<lastBuildDate>Thu, 09 Feb 2012 00:54:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Kirk Munro</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-2227</link>
		<dc:creator><![CDATA[Kirk Munro]]></dc:creator>
		<pubDate>Mon, 17 Jan 2011 15:19:38 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-2227</guid>
		<description><![CDATA[Sure.  You just need something like this:

powershell.exe -command &quot;&amp; C:\test.ps1 parameter1 parameter2&quot;

You could use named parameters of course. The trick is to make sure you are passing the parameters from inside of your PowerShell session that you are creating, not as parameters to powershell.exe.]]></description>
		<content:encoded><![CDATA[<p>Sure.  You just need something like this:</p>
<p>powershell.exe -command &#8220;&amp; C:\test.ps1 parameter1 parameter2&#8243;</p>
<p>You could use named parameters of course. The trick is to make sure you are passing the parameters from inside of your PowerShell session that you are creating, not as parameters to powershell.exe.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-2220</link>
		<dc:creator><![CDATA[Brian]]></dc:creator>
		<pubDate>Wed, 12 Jan 2011 20:31:17 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-2220</guid>
		<description><![CDATA[Is there a way to run a Powershell command from the run dialog box and also pass parameters to the script you want to run?]]></description>
		<content:encoded><![CDATA[<p>Is there a way to run a Powershell command from the run dialog box and also pass parameters to the script you want to run?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk Munro</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-2146</link>
		<dc:creator><![CDATA[Kirk Munro]]></dc:creator>
		<pubDate>Tue, 21 Dec 2010 14:10:58 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-2146</guid>
		<description><![CDATA[In this case I would use Start-Process.  Start-Process has a -WorkingDirectory parameter that allows you to specify the working directory for the process you start.  I believe this should give you the results that you are looking for.]]></description>
		<content:encoded><![CDATA[<p>In this case I would use Start-Process.  Start-Process has a -WorkingDirectory parameter that allows you to specify the working directory for the process you start.  I believe this should give you the results that you are looking for.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WalkMan</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-2145</link>
		<dc:creator><![CDATA[WalkMan]]></dc:creator>
		<pubDate>Tue, 21 Dec 2010 12:46:28 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-2145</guid>
		<description><![CDATA[But the bigger question is,

When you run a cmd file lets say the following from with in your powershell script
&amp; &quot;C:\ABC (QA)_1.0.7.2\en-us\ABC_QA.cmd&quot;

Contents of ABC_QA.cmd
Msiexec /i ABCInstaller.msi ^
DB.SERVER=ABC\QA ^
APPLICATION.ENV.TYPE=Qa ^
SVCIDENTITY=SVC-QA@ABC.com ^
SVCPASSWORD=xxx ^
LOCAL.EMAILING=&quot;true&quot; ^
/lv &quot;ABC_Installer_QA_Log.txt&quot; 

However when the powershell script is run, it starts the cmd from C:\Documents and Settings\tarora\My Documents and fails to find the correct path to the MSI.

If i make the msi available at &#039;C:\Documents and Settings\tarora\My Documents&#039; it works fine.

1. Am i missing anything?
2. Is there a way to specify the start path for the cmd?]]></description>
		<content:encoded><![CDATA[<p>But the bigger question is,</p>
<p>When you run a cmd file lets say the following from with in your powershell script<br />
&amp; &#8220;C:\ABC (QA)_1.0.7.2\en-us\ABC_QA.cmd&#8221;</p>
<p>Contents of ABC_QA.cmd<br />
Msiexec /i ABCInstaller.msi ^<br />
DB.SERVER=ABC\QA ^<br />
APPLICATION.ENV.TYPE=Qa ^<br />
SVCIDENTITY=SVC-QA@ABC.com ^<br />
SVCPASSWORD=xxx ^<br />
LOCAL.EMAILING=&#8221;true&#8221; ^<br />
/lv &#8220;ABC_Installer_QA_Log.txt&#8221; </p>
<p>However when the powershell script is run, it starts the cmd from C:\Documents and Settings\tarora\My Documents and fails to find the correct path to the MSI.</p>
<p>If i make the msi available at &#8216;C:\Documents and Settings\tarora\My Documents&#8217; it works fine.</p>
<p>1. Am i missing anything?<br />
2. Is there a way to specify the start path for the cmd?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk Munro</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1398</link>
		<dc:creator><![CDATA[Kirk Munro]]></dc:creator>
		<pubDate>Thu, 08 Oct 2009 03:31:18 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1398</guid>
		<description><![CDATA[For your example command to work from outside of PowerShell (for example, in cmd.exe), you need to run it like this:

PowerShell &quot;&amp; &quot;&quot;&quot;&quot;C:\Some Long Path\Script.ps1&quot;&quot;&quot;&quot; &quot;&quot;&quot;&quot;C:\Another Long Path To Some Input File.txt&quot;&quot;&quot;&quot;&quot;

Here&#039;s how this breaks down.  First the string is evaluated where it is executed (in cmd.exe).  When the evaluation replaces adjacent double-quotes with a single double-quote, our command string resolves to this:

&amp; &quot;&quot;C:\Some Long Path\Script.ps1&quot;&quot; &quot;&quot;C:\Another Long Path To Some Input File.txt&quot;&quot;

Then this string is passed into PowerShell as a double-quoted string.  In the double-quoted string, a pair of adjacent double-quotes are again converted to one double-quote, and the string command resolves to this:

&amp; &quot;C:\Some Long Path\Script.ps1&quot; &quot;C:\Another Long Path To Some Input File.txt&quot;

That&#039;s the command you want to execute, so you&#039;re good to go.

This gets a lot easier in PowerShell 2.0 with some new arguments on the powershell.exe command.

If you wanted to run the same command from within PowerShell, you would do it like this:

PowerShell &quot;&amp; &quot;&quot;C:\Some Long Path\Script.ps1&quot;&quot; &quot;&quot;C:\Another Long Path To Some Input File.txt&quot;&quot;&quot;]]></description>
		<content:encoded><![CDATA[<p>For your example command to work from outside of PowerShell (for example, in cmd.exe), you need to run it like this:</p>
<p>PowerShell &#8220;&amp; &#8220;&#8221;"&#8221;C:\Some Long Path\Script.ps1&#8243;&#8221;"&#8221; &#8220;&#8221;"&#8221;C:\Another Long Path To Some Input File.txt&#8221;"&#8221;"&#8221;</p>
<p>Here&#8217;s how this breaks down.  First the string is evaluated where it is executed (in cmd.exe).  When the evaluation replaces adjacent double-quotes with a single double-quote, our command string resolves to this:</p>
<p>&amp; &#8220;&#8221;C:\Some Long Path\Script.ps1&#8243;&#8221; &#8220;&#8221;C:\Another Long Path To Some Input File.txt&#8221;"</p>
<p>Then this string is passed into PowerShell as a double-quoted string.  In the double-quoted string, a pair of adjacent double-quotes are again converted to one double-quote, and the string command resolves to this:</p>
<p>&amp; &#8220;C:\Some Long Path\Script.ps1&#8243; &#8220;C:\Another Long Path To Some Input File.txt&#8221;</p>
<p>That&#8217;s the command you want to execute, so you&#8217;re good to go.</p>
<p>This gets a lot easier in PowerShell 2.0 with some new arguments on the powershell.exe command.</p>
<p>If you wanted to run the same command from within PowerShell, you would do it like this:</p>
<p>PowerShell &#8220;&amp; &#8220;&#8221;C:\Some Long Path\Script.ps1&#8243;&#8221; &#8220;&#8221;C:\Another Long Path To Some Input File.txt&#8221;"&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivan</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1397</link>
		<dc:creator><![CDATA[Ivan]]></dc:creator>
		<pubDate>Thu, 08 Oct 2009 02:53:39 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1397</guid>
		<description><![CDATA[Intesting, but what about this scenario:

From a command prompt
C:\&gt;PowerShell.exe &quot;C:\Some Long Path\Script.ps1&quot; &quot;C:\Another Long Path To Some Input File.txt&quot;

The Powershell script itself will execute, but it&#039;s choking on the .txt file.  Single quotes on the .txt file don&#039;t file the problem.]]></description>
		<content:encoded><![CDATA[<p>Intesting, but what about this scenario:</p>
<p>From a command prompt<br />
C:\&gt;PowerShell.exe &#8220;C:\Some Long Path\Script.ps1&#8243; &#8220;C:\Another Long Path To Some Input File.txt&#8221;</p>
<p>The Powershell script itself will execute, but it&#8217;s choking on the .txt file.  Single quotes on the .txt file don&#8217;t file the problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc Magnin</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1318</link>
		<dc:creator><![CDATA[Marc Magnin]]></dc:creator>
		<pubDate>Wed, 29 Jul 2009 11:22:36 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1318</guid>
		<description><![CDATA[I&#039;have just found a better way by using the [diagnostics.process] class cause i need to wait the end of execution :

[code]
 if($command -match &quot;(?.*\.[A-Za-z]+\s)(?.*)&quot;){
     $com =$Matches.appPath.trim()
     $args =  $Matches.appArgs.trim()
     [diagnostics.process]::start($com, $args).WaitForExit()
}
[/code]


Marc Magnin,
Pourquoi faire simple quand on peut faire compliqué ?!]]></description>
		<content:encoded><![CDATA[<p>I&#8217;have just found a better way by using the [diagnostics.process] class cause i need to wait the end of execution :</p>
<pre class="brush: plain;">
 if($command -match "(?.*\.[A-Za-z]+\s)(?.*)"){
     $com =$Matches.appPath.trim()
     $args =  $Matches.appArgs.trim()
     [diagnostics.process]::start($com, $args).WaitForExit()
}
</pre>
<p>Marc Magnin,<br />
Pourquoi faire simple quand on peut faire compliqué ?!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc Magnin</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1317</link>
		<dc:creator><![CDATA[Marc Magnin]]></dc:creator>
		<pubDate>Wed, 29 Jul 2009 10:18:07 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1317</guid>
		<description><![CDATA[Hello,

I&#039;m replying to this old post because it helped me to find a way to dynamically call / run program requiring arguments like :

C:\Program files\Program\program.exe /verysilent /norestart /LoadInf=&quot;.\conf.ini&quot;

This work if I write directly the full command in powershell like :

[code]
&amp; C:\Program files\Program\program.exe /verysilent /norestart /LoadInf=&quot;.\conf.ini&quot;
[/code]

Great!
But I have no idea of the command in advance... Heck!
So I tried several things like :

[code]
&amp; $fullCommandString
&amp; $commandString $argsString
. $commandString $argsString
. $quotedCommandString $quotedArgsString
powershell -command &quot;&quot;
invoke-item $commandString $argsString
[/code]
etc........

but I still had errors caused by space in &quot;Program files&quot; or slash of arguments etc...

The way I found is to pass a string for the command and an array of string for arguments :
(here I directly wrote the command in the code by in reality, $command is feeded from and XML file)

[code]
$command = &quot;C:\Program files\Program\program.exe /verysilent /norestart /LoadInf=&#039;.\conf.ini&#039;&quot;
if($command -match &quot;(?.*\.[A-Za-z]+\s)(?.*)&quot;){
   $args = [regex]::Split($Matches.appArgs.trim(), &quot;\s&quot; )
   &amp; $Matches.appPath.trim() $args
}
[/code]

Hope thats helps.

Marc Magnin,
Pourquoi faire simple quand on peut faire compliqué ?!]]></description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I&#8217;m replying to this old post because it helped me to find a way to dynamically call / run program requiring arguments like :</p>
<p>C:\Program files\Program\program.exe /verysilent /norestart /LoadInf=&#8221;.\conf.ini&#8221;</p>
<p>This work if I write directly the full command in powershell like :</p>
<pre class="brush: plain;">
&amp; C:\Program files\Program\program.exe /verysilent /norestart /LoadInf=".\conf.ini"
</pre>
<p>Great!<br />
But I have no idea of the command in advance&#8230; Heck!<br />
So I tried several things like :</p>
<pre class="brush: plain;">
&amp; $fullCommandString
&amp; $commandString $argsString
. $commandString $argsString
. $quotedCommandString $quotedArgsString
powershell -command ""
invoke-item $commandString $argsString
</pre>
<p>etc&#8230;&#8230;..</p>
<p>but I still had errors caused by space in &#8220;Program files&#8221; or slash of arguments etc&#8230;</p>
<p>The way I found is to pass a string for the command and an array of string for arguments :<br />
(here I directly wrote the command in the code by in reality, $command is feeded from and XML file)</p>
<pre class="brush: plain;">
$command = "C:\Program files\Program\program.exe /verysilent /norestart /LoadInf='.\conf.ini'"
if($command -match "(?.*\.[A-Za-z]+\s)(?.*)"){
   $args = [regex]::Split($Matches.appArgs.trim(), "\s" )
   &amp; $Matches.appPath.trim() $args
}
</pre>
<p>Hope thats helps.</p>
<p>Marc Magnin,<br />
Pourquoi faire simple quand on peut faire compliqué ?!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk Munro</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1058</link>
		<dc:creator><![CDATA[Kirk Munro]]></dc:creator>
		<pubDate>Tue, 12 May 2009 14:55:12 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1058</guid>
		<description><![CDATA[Confusion comes with any new technology, and PowerShell is definitely not immune to that.  There are some things that don&#039;t seem to make sense.  We call them &quot;gotchas&quot;.

I&#039;d love to hear more about &quot;the many rough edges to PowerShell that make it a pain&quot; to see if I can do anything to help.

Also I&#039;d like to know what sort of integration you are looking for with PowerShell and Windows.  With Windows 7 and Windows Server 2008 R2, it is shipped as part of the operating system and installed by default, which is a great first step.  But I&#039;d like to know what specific scenarios come to mind for you when you think about stronger integration into Windows.  Please elaborate if you have time. :)]]></description>
		<content:encoded><![CDATA[<p>Confusion comes with any new technology, and PowerShell is definitely not immune to that.  There are some things that don&#8217;t seem to make sense.  We call them &#8220;gotchas&#8221;.</p>
<p>I&#8217;d love to hear more about &#8220;the many rough edges to PowerShell that make it a pain&#8221; to see if I can do anything to help.</p>
<p>Also I&#8217;d like to know what sort of integration you are looking for with PowerShell and Windows.  With Windows 7 and Windows Server 2008 R2, it is shipped as part of the operating system and installed by default, which is a great first step.  But I&#8217;d like to know what specific scenarios come to mind for you when you think about stronger integration into Windows.  Please elaborate if you have time. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1056</link>
		<dc:creator><![CDATA[Nick]]></dc:creator>
		<pubDate>Mon, 11 May 2009 22:50:33 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-1056</guid>
		<description><![CDATA[Thanks for the explanation.

Unfortunately, this is one of the many rough edges to powershell that make it a pain.  Powershell needs to become better integrated into windows before I will really start using it.  The end result that Yang Li pointed out -- confusion -- is all too prevalent in Powershell.]]></description>
		<content:encoded><![CDATA[<p>Thanks for the explanation.</p>
<p>Unfortunately, this is one of the many rough edges to powershell that make it a pain.  Powershell needs to become better integrated into windows before I will really start using it.  The end result that Yang Li pointed out &#8212; confusion &#8212; is all too prevalent in Powershell.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Encrypt App.config section using PowerShell as a Post-build event : Philippe</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-978</link>
		<dc:creator><![CDATA[Encrypt App.config section using PowerShell as a Post-build event : Philippe]]></dc:creator>
		<pubDate>Tue, 24 Mar 2009 12:56:34 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-978</guid>
		<description><![CDATA[[...] There are lot of quotes, but this is the only way to get it working. For detailed explanations on why, see this post: Invoking a PowerShell script from cmd.exe (or Start &#124; Run). [...]]]></description>
		<content:encoded><![CDATA[<p>[...] There are lot of quotes, but this is the only way to get it working. For detailed explanations on why, see this post: Invoking a PowerShell script from cmd.exe (or Start | Run). [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Hanson</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-940</link>
		<dc:creator><![CDATA[Tim Hanson]]></dc:creator>
		<pubDate>Thu, 19 Feb 2009 09:17:47 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-940</guid>
		<description><![CDATA[Thanks for the info and examples. i guess it goes without saying, but it&#039;s important to distinguish typographical open and close quotes from the simple ascii variety intended here. folks coming from unix background might be confused, because &quot;back-quote&quot; had a special meaning there. I&#039;ll be curious how my &#039;quotes&#039; appear after posting. :)]]></description>
		<content:encoded><![CDATA[<p>Thanks for the info and examples. i guess it goes without saying, but it&#8217;s important to distinguish typographical open and close quotes from the simple ascii variety intended here. folks coming from unix background might be confused, because &#8220;back-quote&#8221; had a special meaning there. I&#8217;ll be curious how my &#8216;quotes&#8217; appear after posting. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt (QA Dev)</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-928</link>
		<dc:creator><![CDATA[Matt (QA Dev)]]></dc:creator>
		<pubDate>Wed, 04 Feb 2009 19:14:14 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-928</guid>
		<description><![CDATA[I ran into the same need for double quotes when executing .VBS files with parameters from a C# Application.

I was looking to execute a .PS1 file from a C# app and I am gald I came across this info.

Thank you!]]></description>
		<content:encoded><![CDATA[<p>I ran into the same need for double quotes when executing .VBS files with parameters from a C# Application.</p>
<p>I was looking to execute a .PS1 file from a C# app and I am gald I came across this info.</p>
<p>Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leif Alire</title>
		<link>http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-116</link>
		<dc:creator><![CDATA[Leif Alire]]></dc:creator>
		<pubDate>Thu, 01 Nov 2007 17:51:37 +0000</pubDate>
		<guid isPermaLink="false">http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/#comment-116</guid>
		<description><![CDATA[Very good article and a great job on the explanations after each example.]]></description>
		<content:encoded><![CDATA[<p>Very good article and a great job on the explanations after each example.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

