Hi, PS Guru?
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'm a bit lost here.
first, I found out the forum what I eventually want to do, http://trycatchfail.com/blog/post/The-trials-and-tribulations-of-using-MSDeploy-with-PowerShell.aspx
But I found out using cmd /c, running msdeploy.exe is not easy actually that the following function doesn't work
function PushToTarget([string]$server, [string]$remotePath, [string]$localPath) { cmd.exe /C $("msdeploy.exe -verb:sync -source:contentPath=`"{0}`" -dest:computerName=`"{1}`",contentPath=`"{2}`" -whatif" -f $localPath, $server, $remotePath ) }
So, I wrote and came down to the following script.
$envMsDeploy = $env:msdeploy
$DirMsDeploy = split-Path -Parent $envMsDeploy
# defined the current location to C:Program FilesIISMicrosoft Web Deploy V2
set-location $DirMsDeploy
$arg = @(
'-verb:sync';
'-source:contentPath=' + $buildDroppedLocation;
'-dest:contentPath=' + $destinationPath;
' -whatif > c:tempmsdeploy.log'
)
$runMSDeploy = ($DirMsDeploy + "Msdeploy.exe " + $arg)
When I outfile $runMSDeploy, it shows "C:Program FilesIISMicrosoft Web Deploy V2Msdeploy.exe -verb:sync -source:contentPath=c:source Path -dest:contentPath=\unc path to a remoted serverfolderso, it stores necessary information to run MSdeploy with the necessary parameters I want to have.
But since it contains C:Program FilesIISMicrosoft Web Deploy V2msdeploy.exe, I get the error message, "cmd.exe : 'C:Program' is not recognized as an internal or external command".
I am kinda under why the error happens but I can't seem to find a better answer yet. cmd.exe runs from c:windowssystem32 and then the created script run c:program filesIISMicrosoft Web Deploy V2Msdeploy.exe from c:windowssystem32 directory.
This is where I'm trying to figure out.
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?