Home > BizTalk Server, Powershell > Automating\Silent Installation of BizTalk Deployment Framework (BTDF) using Powershell

Automating\Silent Installation of BizTalk Deployment Framework (BTDF) using Powershell


To do a silent install/automate the installation of BizTalk Application using BizTalk Deployment Framework you can use the Powershell script below:


<#
.SYNOPSIS
 Automates BizTalk Application deployment using BTDF 5.0

.DESCRIPTION
 Automates BizTalk Application deployment using BTDF 5.0
  Steps:
   1. It installs the MSI on the specified application path
   2. Calls EnvironmentSettingsExporter to generate the settings xml
   3. Updates Environment Variables
   4. Executes the MSBuild with parameters

.NOTES
 File Name: Install-BizTalkApplication.ps1
 Author: Randy Aldrich Paulo
 Prerequisite: Powershell 2.0, BizTalk Deployment Framework 5.0, BizTalk Server 2010

.PARAMETER MsiFile
 MSI File generated using BizTalk Deployment Framework 5.0

.PARAMETER ApplicationInstallPath
 Location wherein the resource files will be copied, it will be use by the BTDF during the deployment

.PARAMETER Environment
 Name of environment (Local,Dev,Test,Prod) to be used, this value will be passed to
 EnvironmentSettingsExporter and willbe used to construct the environment variable: ENV_SETTINGS

.EXAMPLE
 Install-BizTalkApplication -MsiFile "E:\Installer\Application 1\Application1.msi"
 -ApplicationInstallPath "E:\Program Files\Application 1"
 -Environment DEV

.EXAMPLE
 Install-BizTalkApplication -msi "E:\Installer\Application 1\Application1.msi"
 -path "E:\Program Files\Application 1"
 -env TEST

.EXAMPLE
 Install-BizTalkApplication "E:\Installer\Application 1\Application1.msi"
 "E:\Program Files\Application 1" TEST

.EXAMPLE
 Install-BizTalkApplication "E:\Installer\Application 1\Application1.msi"
 "E:\Program Files\Application 1" TEST -SkipUndeploy $false

#>
function Install-BizTalkApplication
{
 param(
  [Parameter(Position=0,Mandatory=$true,HelpMessage="Msi file should be existing")]
  [ValidateScript({Test-Path $_})]
  [Alias("msi")]
  [string]$MsiFile,
  
  [Parameter(Position=1,HelpMessage="Path wherein the resource file will be installed")]
  [Alias("path")]
  [string]$ApplicationInstallPath,
  
  [Parameter(Position=2,Mandatory=$true,HelpMessage="Only valid parameters are Local,Dev,Test and Prod")]
  [Alias("env")]
  [ValidateSet("Local","Dev","Prod","Test")]
  [string]$Environment,

  [bool]$BTDeployMgmtDB=$true,
  [bool]$SkipUndeploy=$true
  )

 $ErrorActionPreference="Stop"

 #Step 1 : Run MSI 
  $script =
  {
      $args = "-i $MsiFile INSTALLDIR=`"$ApplicationInstallPath`" /qn /norestart"
   Write-Host " Installing MSI File.." -ForegroundColor Cyan
   Write-Host "  MSI File: $MsiFile" -ForegroundColor DarkGray
   Write-Host "      Args: $args" -ForegroundColor DarkGray
   
   $exitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList $args -Wait -Passthru).ExitCode
   Write-Host " Exit Code: $exitCode"
   
   if($exitCode -ne 0)
   {
    Write-Error "Installing $MsiFile failed!, Exit Code: $exitCode"
   }
   Write-Host " Installed MSI success.." -ForegroundColor Green
   Write-Host ""
  }
  Invoke-Command -scriptblock $script
 
 #Step 2 : Run MSBuild & Deploy
 
  $script=
  {
   <# Start Step 2.2 Run EnvironmentSettingsExporter, this one generates the xml file
   (Exported_DevSettings.xml, Exported_LocalSettings.xml etc..)
   #>
   $args = "`"" + (Join-Path $ApplicationInstallPath "Deployment\EnvironmentSettings\SettingsFileGenerator.xml") + "`"" + " Deployment\EnvironmentSettings"
   $exePath = ("`"" + (Join-Path $ApplicationInstallPath "\Deployment\Framework\DeployTools\EnvironmentSettingsExporter.exe") + "`"")
   Write-Host " Generating Environment Settings File.."  -ForegroundColor Cyan
   Write-Host " Location: $exePath" -ForegroundColor DarkGray
   Write-Host "  Args: $args" -ForegroundColor DarkGray

   $exitCode = (Start-Process -FilePath $exePath -ArgumentList $args -Wait -PassThru).ExitCode
   Write-Host " Exit Code: $exitCode"
   
   if($exitCode -ne 0)
   {
    Write-Error " Generating Environment Settings File failed!, Exit Code: $exitCode"
   }
   Write-Host " Generated Environment Settings File. " -ForegroundColor Green
   Write-Host ""
   <# End Step 2.2 Run EnvironmentSettingsExporter, this one generates the xml file
   (Exported_DevSettings.xml, Exported_LocalSettings.xml etc..)#>
   <# Start Step 2.3 Set the Environment Variables ENV_SETTINGS and BT_DEPLOY_MGMT_DB #>
   $settingsFile = "Deployment\EnvironmentSettings\Exported_{0}Settings.xml" -f $Environment
   $EnvSettings =Join-Path $ApplicationInstallPath $settingsFile

   Write-Host " Setting Environment Variables"  -ForegroundColor Cyan
   
   Write-Host "      ENV_SETTINGS = $EnvSettings" -ForegroundColor DarkGray;
   Set-Item Env:\ENV_SETTINGS -Value $EnvSettings
   
   Write-Host  " BT_DEPLOY_MGMT_DB = $BTDeployMgmtDB"  -ForegroundColor DarkGray;
   Set-Item Env:\BT_DEPLOY_MGMT_DB -Value $BTDeployMgmtDB
   
   Write-Host " Setted Environment Variables"  -ForegroundColor Green
   Write-Host ""
   <# End Step 2.3 Set the Environment Variables ENV_SETTINGS and BT_DEPLOY_MGMT_DB #>
   
   <# Start Step 2.4 Execute MS Build with parameters #>
   
   #Get .NET Version
   $dotNetVersion = gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des | select -fi 1 -exp pschildname
   if($dotNetVersion = "v4.0") { $dotNetVersion = "v4.0.30319" } #Include other info if .NET 4.0
   
   if (Test-Path ( Join-Path $env:windir "Microsoft.NET\Framework\$dotNetVersion\MSBuild.exe" ))
   {
    $BTDFMSBuildPath = Join-Path $env:windir "Microsoft.NET\Framework\$dotNetVersion\MSBuild.exe"
    Write-Host " Using MSBuild $dotNetVersion" -ForegroundColor DarkGray
   }
   else
   {
    Write-Error " MSBuild not found."
   }
   
   #Assign MS Build Params
   $parms="DeployBizTalkMgmtDB=$BTDeployMgmtDB;Configuration=Server;SkipUndeploy=$SkipUndeploy"
   $logger="FileLogger,Microsoft.Build.Engine;logfile=`"" + ( Join-Path $ApplicationInstallPath "DeployResults\DeployResults.txt" ) + "`""
   $btdfFile="`"" +  (Join-Path $ApplicationInstallPath "Deployment\Deployment.btdfproj") + "`""
   $args = "/p:{1} /l:{2} {0}" -f $btdfFile,$parms,$logger
   
   Write-Host " Executing MSBuild from: $BTDFMSBuildPath"  -ForegroundColor Cyan
   Write-Host " ArgList: $args" -ForegroundColor DarkGray
   
   #Check MSBuild Return Code
   $exitCode = (Start-Process -FilePath $BTDFMSBuildPath -ArgumentList $args -Wait -Passthru).ExitCode
   Write-Host " Exit Code: $exitCode"
   Write-Host ""
   if($exitCode -ne 0)
   {
    Write-Error " Error while calling MSBuild, Exit Code: $exitCode"
   }
  
   #Copy Log File
   Write-Host " Copying  Log file."
   $args =  "Deployment\Framework\CopyDeployResults.msbuild /nologo"
   Start-Process -FilePath $BTDFMSBuildPath -ArgumentList $args
   
   <# End Step 2.4 Execute MS Build with parameters #>
  }
 
  Write-Host " Running MS Build and deploying.." -ForegroundColor Cyan
  Invoke-Command -scriptblock $script
  Write-Host " Deployed application" -ForegroundColor Green

}

Download Script (MSWord): Install-BizTalkApplication – Powershell Script 

 

Advertisements
  1. January 31, 2012 at 4:45 pm

    Way to go Randy! Nice share! 🙂

    • January 31, 2012 at 7:59 pm

      :).. Next step is to do a remote install using Windows Powershell Remoting, just need to add computer name as parameter to invoke command and pass the arguments using argslist.

  2. Helge
    April 18, 2012 at 12:46 pm

    Any chance you’ll share that as well?

  3. Helge
    April 20, 2012 at 12:18 pm

    Thanx!

  4. May 2, 2012 at 8:36 pm

    A useful detail to know when you’re running this script on a 64-bit system:

    The $path parameter should be somewhere under “C:\Program Files (x86)”, NOT under “C:\Program Files”.

    If you use “C:\Program Files”, Windows Installer will automatically redirect to “C:\Program Files (x86)”, but the script itself won’t be aware of the redirection, so it will to access files in the incorrect folder.

  5. June 4, 2012 at 5:58 am

    Thanks for creating and posting this script! It is not necessary to set the environment variables ENV_SETTINGS and BT_DEPLOY_MGMT_DB — instead, just pass them to MSBuild.exe as property name/value pairs. Would you be OK including this script in the BTDF 5.0 release?

  6. Ed
    June 12, 2012 at 1:44 pm

    @Randy – thanks for posting this script, I’m hopeful that it will make our BizTalk deployments to multiple environments much easier.

    However at the moment I’m having a problem when running this on a remote server which I wondered if you had any ideas about.

    The MSI is installing correctly, and the msbuild task is kicked off and gets as far as the Target DeployAppDefinition, when I get the error “Error: Unable to validate the given database “BizTalkMgmtDb” and server “SQLSERVER”.

    SQLSERVER does exist, and the database “BizTalkMgmtDb” is hosted on there.

    I have tried various methods of calling the script using both invoke-command and within a pssession,

    After Googling this error I found some suggestions that this was to do with permissions accessing the database, but there are no errors that I can find on the DB Server. The msbuild process in Task Explorer is running under the correct user account when it is spawned by Powershell. I have tried passing in credentials to the Start-Process call to msbuild but this hasn’t helped.

    Any ideas appreciated.

    Thanks, Ed.

  7. Ed
    June 12, 2012 at 3:18 pm

    Further to my previous comment, I’ve broken this down further as follows.
    1. On my BizTalk server, open a Powershell prompt with Administrator rights.
    2. Open a remote Powershell session by running “enter-pssession IP_Addr_of_local_machine -Credential DOMAIN\Username”. The Domain\Username in this case is the same credentials I am logged into the machine with.
    3. Run “BTSTask.exe AddApp -ApplicationName:`”AppName`” -Description:`”AppDescription`”.
    4. This gives the same error as before: “Unable to validate the given database “BizTalkMgmtDb” and server “SQLSERVER”.
    5. If I exit the remote session and run the same command in the same Powershell prompt it then works. This is using the same logged in credentials as I passed when I opened the remote session.

    Ed.

  8. June 12, 2012 at 7:38 pm

    @Ed it could be an issue with double-hop. When using PSRemote, you need to enable CredSSP. See:
    https://randypaulo.wordpress.com/2012/02/27/powershell-missing-shared-custom-modules-when-using-powershelremoting/

  9. Ed
    June 14, 2012 at 10:55 am

    @Randy, thanks a lot for pointing me in the right direction. It was indeed an issue with double-hop, and using CredSSP solved that particular problem. Cheers!

  10. August 2, 2012 at 12:57 pm

    First, thanks to Randy for great script – this has solved lots of problems for me.

    Unfortunately, I have the same problem as Ed but I haven’t been able to resolve. I have used gpedit.msc and Enable-WSManCredSSP to enable delegation from the build server. I’ve also run Enable-WSManCredSSP on the receiving server. I have a parent PS script that runs on the client, this copies Randy’s script to the target server before executing it remotely with the following line:

    Invoke-Command -Session $Session -FilePath .\ExecuteBizTalkAppMSI.ps1 -argumentlist $MSI, $InstallFolderOnTargetServer, $Environment, $DeploymentFolderOnTargetServer

    This fails and when I look in the DeployResults.txt on the receiving server I see the following:
    c:\Program Files (x86)\Vasanta.Int.MIS for BizTalk 2010\Deployment\Framework\BizTalkDeploymentFramework.targets(1195,5): error MSB3073: The command “BTSTask.exe AddApp -ApplicationName:”Vasanta.Int.MIS” -Description:”Vasanta.Int.MIS”” exited with code 1.

    Can you think of anything else I need to check please?

  11. November 22, 2012 at 9:38 am

    The BizTalk server 2010 constructs upon the SOA/ESB and Business Process Management in previous releases with aim to aid organizations widen systems of main process management in a lot more advance.

  12. rajpal
    December 4, 2012 at 12:11 am

    Hi Randy, Thanks for the script, i am trying to run this a for a MSI built with the Deployment framework. The MSI by itself can successfully deploy and undeploy to my Biztalk environments, but when i try to ru your script, i get this error in the DeployResults file:

    Target Clean:
    C:\Program Files (x86)\Warranty\Deployment\Framework\BizTalkDeploymentFramework.WiXSetup.targets(187,5): error : Cannot continue. The OutputPath property is undefined. By default, this property is defined in the .btdfproj in PropertyGroups conditional to Debug and Release configurations.
    Done building target “Clean” in project “Deployment.btdfproj” — FAILED.

    Is there something ive missed out in the Script ?

    • December 4, 2012 at 9:37 am

      Right click the Solution -> Set the Build Configuration to either Debug or Release.

      • Sebastian
        January 10, 2013 at 10:53 am

        Thanks for a great scipt. I would also like to ask about the Output path. When it is defined to Debug for example. Trying to install application on a remote server from MSI I built using your script, it will put all DLLs to -ApplicationInstallPath while the Output path is still defined to look in bin\Debug folder and installation fails as it cannot find DLL in bin\Debug because they are sitting in ApplicationInstallPath. Am I missing something here?

      • January 15, 2013 at 3:26 pm

        Basically the first step in the process is to install the msi file that BTDF generates, it should include all necessary assemblies needed to do a rebuild on the next step which is to call the MSBuild.
        You need to probably tweak some settings in your BTDF file, when BTDF is properly setup you shouldn’t encounter any error.

      • Dreameen
        January 14, 2013 at 8:23 pm

        Hi Randy,
        Why did not you post my question?

  13. Jon
    February 21, 2013 at 1:46 pm

    Hi,

    I get this error “Install-BizTalkApplication : Generating Environment Settings File failed!, Exit Code: -1” when I run the scripot. I think that is some bad in this line: Start-Process -FilePath “C:\BT_PRUEBAS\Deployment\Framework\DeployTools\EnvironmentSettingsExporter.exe” -ArgumentList “C:\BT_PRUEBAS\Deployment\EnvironmentSettings\SettingsFileGenerator.xml” Deployment\EnvironmentSettings -Wait -PassThru”

    Somebody can help me please

  14. March 13, 2013 at 9:04 am

    For debugging, whenever the script return an error, you can go to the install folder (where MSI is installed), open the DeployResults folder (generated by BTDF), then open the text file name DeployResults.txt, it will give you the logs and possibly the cause of error.

  15. RM
    January 9, 2014 at 10:16 pm

    Hi,
    I am trying to utilize this script to Install, Deploy and UnDeploy, UnInstall the BizTalk application through command application(C#). I am able to do UnDeploy(two servers) but not able to Deploy(one server is ok but not the final one). I get this error, error MSB3073: The command “BTSTask.exe AddResource -Type:BizTalkAssembly -Source:”..\BizTalk.Schemas.dll” -ApplicationName:”BizTalkAPP” -Options:GacOnAdd,GacOnImport,GacOnInstall” exited with code -1073741571.

  16. charles.keezer@cbn.org
    February 14, 2014 at 1:29 pm

    Great looking script. I am having the same issue as Sebastian. When I compile the MSI from VS, and then try to run the script I get the error:

    error MSB3021: Unable to copy file “..\Schemas\bin\Debug\Schemas.dll” to “obj\Debug\redist\Schemas.dll”. Could not find a part of the path ‘..\Schemas\bin\Debug\Schemas.dll’

    I understand why the error is happening, however I am not sure what needs to change in the btdf.proj file to have it look in the deployment folder for all .dll files.

  17. May 28, 2014 at 3:08 am

    Charles, if you are seeing that message under PowerShell script execution, then you are running the wrong MSBuild target. The default target is Installer, which builds the MSI. If you’re trying to deploy, then MSBuild needs to run the Deploy target.

  18. steveculshaw
    June 20, 2014 at 10:23 am

    Excellent post, and thanks for sharing the knowledge

  19. June 23, 2014 at 8:13 am

    Thank you very much. This script helps me make silent deployment in my installation package. However in one of my MSI I have a small error which is not a show stopper.

    You have placed ” $ErrorActionPreference=”Stop”” but did not used it. How can I make my deployment go on when there is an error?

    • June 24, 2014 at 6:44 am

      The detial is I want to ignorre the warning about VDIR_UserName. Sincethis is silent I did not included VDIR_Username in any config files. And I’M configuring appPool by another action on my full installation.

  20. neerajser
    July 9, 2014 at 10:06 am

    Hi Randy,
    Thanks for sharing great script. I have a basic question on how to use it.
    I do the following to run your script after saving it on my C drive at the location shown in the file below.

    PS C:\Users\NeerajKumar\documents\windowspowershell> .\Install-BizTalkApplication -MsiFile “C:\Users\NeerajKumar\Desktop
    \Deployment\bin\Release\sdm.pubsub3.sys1-1.0.0.msi” -ApplicationInstallPath “C:\Program Files (x86)\pubsub3 for BizTalk”
    -Environment DEV

    The script does not run or gives any error.
    Is there something I am missing in the script?

    Thanks
    Neeraj

  21. sandydv85venkat
    February 16, 2015 at 9:35 am

    HI randy,
    Very urgent help needed,.
    Am using your wonderful code and i got below issues in the deployresults.log file.
    Am using BTDF 6.0 version,BTS 2013 r2 version.
    Could you please tell me how to get rid of this exception

    Target InitWixDir:
    Using WiX Install Path ‘C:\Program Files\test\Deployment\Developer\WiX’.
    Target Clean:
    C:\Program Files\test\Deployment\Framework\BizTalkDeploymentFramework.WiXSetup.targets(198,5): error : Cannot continue. The OutputPath property is undefined. By default, this property is defined in the .btdfproj in PropertyGroups conditional to Debug and Release configurations.
    Done building target “Clean” in project “Deployment.btdfproj” — FAILED.

    Done building project “Deployment.btdfproj” — FAILED.

    Build FAILED.

    C:\Program Files\test\Deployment\Framework\BizTalkDeploymentFramework.WiXSetup.targets(198,5): error : Cannot continue. The OutputPath property is undefined. By default, this property is defined in the .btdfproj in PropertyGroups conditional to Debug and Release configurations.
    0 Warning(s)
    1 Error(s)

  22. March 4, 2015 at 7:11 pm

    sandydv85venkat – You must pass /t:Deploy to MSBuild on the deployment. You’re implicitly running /t:Installer.

  23. Pandit.
    July 27, 2015 at 1:18 pm

    Hi Randy, Thank you for this wonderful script. I am calling this ps script from TFS Build. The TFS Build is failing and it seems the .ExitCode is not getting a correct status code. Seems like it is getting a null back and the below check fails.
    if($exitCode -ne 0)
    {
    Write-Error “Installing $MsiFile failed!, Exit Code: $exitCode”
    }
    Write-Host ” Installed MSI success..” -ForegroundColor Green
    Write-Host “”
    }
    Do you know what is wrong here?

  24. RavinJP
    August 25, 2016 at 3:20 pm

    Hi Randy, Great script. This script is working fine where Host Instances belongs to my one server only .But this script fails where I have multiple host instances with the same name i.e (multi server installation )

  1. February 13, 2012 at 6:13 pm
  2. April 3, 2012 at 7:06 am
  3. March 8, 2016 at 2:09 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: