Tfs Deployer + PowerShell + MSdeploy

Mar 28, 2011 at 7:10 PM

Hello, experts,

I know this is the forum where I could discuss about the TFS Deployer but I need some help to make TFS Deployer working with MS deploy deployment. I made the things working pretty closely (I hope) but making TFS deployer working with MS deploy is not easy. Actually more likely MS Deploy in Powershell giving me lots of headaches.

I found a forum showing at http://trycatchfail.com/blog/post/The-trials-and-tribulations-of-using-MSDeploy-with-PowerShell.aspx, which I want to be at.

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 )
}

But so far, I have.

$buildDroppedLocation = $TfsDeployerBuildDetail.DropLocation + "\Release\_PublishedWebsites\"

$RemoteServerName = "gftesttfs2010"
$DestinationPath = "\\some UNC path\deployed"

$envMsDeploy = $env:msdeploy
$DirMsDeploy = split-Path -Parent $envMsDeploy
   
# defined the current location to C:\Program Files\IIS\Microsoft Web Deploy V2
set-location $DirMsDeploy
 
  $arg = @(
    '-verb:sync';
    '-source:contentPath=' + $buildDroppedLocation;
    '-dest:contentPath=' + $destinationPath;
    #' -whatif > c:\temp\msdeploy.log'
    ' > c:\temp\msdeploy.log';
  )

  $cmdCommand = "@echo off `n"
  $cmdCommand = "cd " + $DirMsDeploy # it prints out cd c:\program files\IIS\Microsoft Web Deploy V2\
  $cmdCommand | out-File c:\temp\MsDeployTest.Bat
  $runMSDeploy = "Msdeploy.exe " + $arg
  $runMSDeploy | Out-file c:\temp\MsDeployTest.bat -Append

  $createDate = (Get-Date -format 'yyyy-mm-dd hh-mm-ss')
 
  $process = [WMIClass]"\\$RemoteServerName\Root\CIMV2:win32_Process"
  $result = $process.Create("C:\temp\MsDeployTest.bat")

In my MSDeployTest.Bat file, it changes the directory to MS deploy path so that I can run the following command,
"msdeploy -verb:sync -source:Contentpath=c:\\source path -dest:contentPath=\\destination UNC path\deployed > c:\temp\deployed.log"

1. Batch file doesn't run due to the error, " '' is not recognized as an internal or external command, operable program or batch file."

2. When I run MSdeploy command only in cmd, it works fine; it copies from source to destination successfully.

Can some help me to figure out my Puzzle? I read from IIS.NET forum saying that MSDeploy PSSnapin yanked out from Powershell at the last minute.
Is this impossible task to do?

Thanks,

John.

Coordinator
Mar 28, 2011 at 9:47 PM

This works for me:

#BEGIN
$MsDeployDir = (Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\MSDeploy).'(default)'
$MsDeployExe = $MsDeployDir | Join-Path -ChildPath msdeploy.exe
& cmd.exe /c $('" "{0}" -verb:sync -source:contentPath="{1}" -dest:contentPath="{2}" -whatif "' -f $MSDeployExe, $BuildDroppedLocation, $DestinationPath)
#END

- Jason 

Mar 28, 2011 at 10:57 PM

Omg...wow....

It is working so great that I can expand the script to make do more and super thank to you, Jason.

Could I ask you one more favor? I'm just learned to use PowerShell about a month and I do understand that learning the PS is a bit more stiffer than I expected.

What would you recommend to learn PS every day? Would you mind to recommend me a book or some study material?

Thank you so much again for the great tool and snippet.

John.

Mar 29, 2011 at 1:02 AM

Jason,

Could I have one more question?

I submitted a forum just now to MS at http://social.msdn.microsoft.com/Forums/en-US/tfsgeneral/thread/a978c204-2e0e-4179-b845-b543472e8537

Now I'm trying to do use -skip:objectName=".*web\.config" inside of this snippet as putting the -skip:objectName parameter directly like & cmd.exe /c $('" "{0}" -verb:sync -source:contentPath="{1}" -dest:contentPath="{2}" -skipobjectname=filepath,absolutePath="*.web\.config" -whatif "' -f $MSDeployExe, $BuildDroppedLocation, $DestinationPath)

or used as passing the paremeters like

$excludeFile=".*web\.config"

& cmd.exe /c $('" "{0}" -verb:sync -source:contentPath="{1}" -dest:contentPath="{2}" -skipobjectname=filepath,absolutePath="{3}" -whatif "' -f $MSDeployExe, $BuildDroppedLocation, $DestinationPath, $excludeFile)

However, it doesn't exclude because -skip:objectName=filePath,abolutePath= doesn't seem like working.

Thing is, when manually create and run the whole msdeploy command with the skip parameter, it exclude them the way I wanted.

Any idea how I could approach this?

John.

Mar 30, 2011 at 5:04 PM

I realized that I defined $excludeFile wrong and corrected to $excludeFile =  [string]$excludeFile = "\\.*web\.config"

Then, it start to exclude the I want to.

John.