<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'sectionid:201' matching tag 'IIS 7'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=sectionid%3A201&amp;tag=IIS+7&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'sectionid:201' matching tag 'IIS 7'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>running MSDeploy in Powershell</title><link>http://powershell.com/cs/forums/thread/9746.aspx</link><pubDate>Fri, 25 Mar 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:9746</guid><dc:creator>wannabeshredding</dc:creator><description>&lt;p&gt;Hi, PS Guru? &lt;/p&gt;
&lt;p&gt;I have been trying to write a PS deployment script to automate the deployment process bit for my work. I did some research for couple of weeks now and I&amp;#39;m a bit lost here.&lt;/p&gt;
&lt;p&gt;first, I found out the forum what I eventually want to do, &lt;a href="http://trycatchfail.com/blog/post/The-trials-and-tribulations-of-using-MSDeploy-with-PowerShell.aspx"&gt;http://trycatchfail.com/blog/post/The-trials-and-tribulations-of-using-MSDeploy-with-PowerShell.aspx&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But I found out using cmd /c, running msdeploy.exe is not easy actually that the following function doesn&amp;#39;t work &lt;/p&gt;
&lt;pre class="class"&gt;function PushToTarget([string]$server, [string]$remotePath, [string]$localPath) {
    cmd.exe /C $(&amp;quot;msdeploy.exe -verb:sync -source:contentPath=`&amp;quot;{0}`&amp;quot; -dest:computerName=`&amp;quot;{1}`&amp;quot;,contentPath=`&amp;quot;{2}`&amp;quot; -whatif&amp;quot; -f $localPath, $server, $remotePath )
}&lt;/pre&gt;
&lt;pre class="class"&gt;&lt;/pre&gt;
&lt;pre class="class"&gt;So, I wrote and came down to the following script.&lt;/pre&gt;
&lt;pre class="class"&gt;&lt;/pre&gt;
&lt;pre class="class"&gt;$envMsDeploy = $env:msdeploy&lt;br /&gt;$DirMsDeploy = split-Path -Parent $envMsDeploy&lt;/pre&gt;
&lt;pre class="class"&gt;# defined the current location to C:\Program Files\IIS\Microsoft Web Deploy V2 &lt;br /&gt;set-location $DirMsDeploy &lt;/pre&gt;
&lt;pre class="class"&gt;&lt;/pre&gt;
&lt;pre class="class"&gt;$arg = @(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39;-verb:sync&amp;#39;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39;-source:contentPath=&amp;#39; + $buildDroppedLocation;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39;-dest:contentPath=&amp;#39; + $destinationPath;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39; -whatif &amp;gt; c:\temp\msdeploy.log&amp;#39;&lt;br /&gt; )&lt;br /&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre class="class"&gt;$runMSDeploy = ($DirMsDeploy + &amp;quot;\Msdeploy.exe &amp;quot; + $arg) &lt;/pre&gt;
&lt;pre class="class"&gt;&lt;/pre&gt;
&lt;pre class="class"&gt;When I outfile $runMSDeploy, it shows &amp;quot;C:\Program Files\IIS\Microsoft Web Deploy V2\Msdeploy.exe -verb:sync -source:contentPath=c:\source Path -dest:contentPath=\\unc path to a remoted server\folderso, it stores necessary information to run MSdeploy with the necessary parameters I want to have.&lt;/pre&gt;
&lt;pre class="class"&gt;But since it contains C:\Program Files\IIS\Microsoft Web Deploy V2\msdeploy.exe,  I get the error message, &amp;quot;cmd.exe : &amp;#39;C:\Program&amp;#39; is not recognized as an internal or external command&amp;quot;. &lt;/pre&gt;
&lt;pre class="class"&gt;I am kinda under why the error happens but I can&amp;#39;t seem to find a better answer yet. cmd.exe runs from c:\windows\system32\ and then the created script run c:\program files\IIS\Microsoft Web Deploy V2\Msdeploy.exe from c:\windows\system32 directory.&lt;/pre&gt;
&lt;pre class="class"&gt;This is where I&amp;#39;m trying to figure out.&lt;/pre&gt;
&lt;pre class="class"&gt;How can I run this without putting $runMSDeploy into a batch file? Is there any cmlet I can use to run $runMSDeploy? Invoke-command or Invoke-Expression?&lt;/pre&gt;
&lt;pre class="class"&gt;&lt;/pre&gt;</description></item></channel></rss>