-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathInstallBizTalkApplication.ps1
183 lines (141 loc) · 4.93 KB
/
InstallBizTalkApplication.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
$ErrorActionPreference = "Stop"
function Wrap-Arguments($Arguments)
{
return $Arguments | % {
[string]$val = $_
#calling msiexec fails when arguments are quoted
if (($val.StartsWith("/") -and $val.IndexOf(" ") -eq -1) -or ($val.IndexOf("=") -ne -1) -or ($val.IndexOf('"') -ne -1)) {
return $val
}
return '"{0}"' -f $val
}
}
function Start-Process2($FilePath, $ArgumentList, [switch]$showCall)
{
$ArgumentListString = (Wrap-Arguments $ArgumentList) -Join " "
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $FilePath
$pinfo.UseShellExecute = $false
$pinfo.CreateNoWindow = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.RedirectStandardError = $true
$pinfo.Arguments = $ArgumentListString;
$pinfo.WorkingDirectory = $pwd
$exitCode = 0
if ($showCall) {
$x = Write-Output "$FilePath $ArgumentListString"
}
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$started = $p.Start()
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
$x = Write-Output $stdout
$x = Write-Output $stderr
$exitCode = $p.ExitCode
return $exitCode
}
& {
Write-Output "Installing MSI"
Write-Host " Current Directory: $(get-location)" -f Gray
Write-Host " Full Script Path: $PSScriptRoot" -f Gray
$files = get-childitem "$PSScriptRoot\*.msi"
Write-Host " files: $files" -f Gray
foreach ($file in $files)
{
$MsiFilePath = $file.FullName
}
Write-Host " MsiFilePath: $MsiFilePath" -f Gray
Write-Host " Action: $Action" -f Gray
Write-Host
if ((Get-Command msiexec) -Eq $Null) {
throw "Command msiexec could not be found"
}
if (!(Test-Path $MsiFilePath)) {
throw "Could not find the file $MsiFilePath"
}
$actionOption = "/i"
$actionOptionFile = Resolve-Path $MsiFilePath
$logOption = "/L*"
$logOptionFile = "$MsiFilePath.log"
$quiteOption = "/qn"
$noRestartOption = "/norestart"
$options = @($actionOption, $actionOptionFile, $logOption, $logOptionFile, $quiteOption, $noRestartOption)
$exePath = "msiexec.exe"
$exitCode = Start-Process2 -FilePath $exePath -ArgumentList $options -ShowCall
Write-Output "Exit Code was! $exitCode"
if (Test-Path $logOptionFile) {
Write-Output "Reading installer log"
$logfile = Get-Content $logOptionFile
Write-Output $logfile
foreach($line in $logfile) {
if ($line.StartsWith("Property(S): INSTALLDIR")) {
$INSTALLDIR = $line.Split("=")[1].Trim()
}
if ($line.StartsWith("Property(S): MSBUILDPATH")) {
$MSBUILDPATH = $line.Split("=")[1].Trim()
}
}
} else {
Write-Output "No logs were generated"
}
if ($exitCode -Ne 0) {
$errorCodeString = $exitCode.ToString()
$errorMessage = $errorCodeString
throw "Error code $exitCode was returned: $errorMessage"
}
$DeployToDatabase = "True"
$InstallDirectory = $INSTALLDIR
$SkipUndeploy= "False"
$LogFileName = "$InstallDirectory\" + "logfile01"
$MSBuildPath = $MSBUILDPATH
$PackagePath = $PSScriptRoot
$BTDFSettingsFile = "$PackagePath\" + "Exported_RMSettings.xml"
$hashConfig = $null
$hashConfig = @{}
[xml]$configFile = Get-Content "$BTDFSettingsFile"
$errorActionPreference = 'Stop'
foreach( $property in $configFile.settings.property)
{
write-host "property.InnerText : " + "$property.InnerText"
$Inner = $property.InnerText
#write-host "Inner : $Inner"
$Inner = $Inner -replace "#{", ""
#write-host "Inner : $Inner"
$Inner = $Inner -replace "}", ""
#write-host "Inner : $Inner"
#found issue with . in names
$Inner = $Inner -replace "\.", "_"
write-host "Inner : $Inner"
try
{
$hashConfig.Add($property.InnerText, (get-item env:$Inner).Value)
}
catch
{
Write-host "$Inner not found"
throw
}
}
$hashConfig
Rename-Item "$BTDFSettingsFile" "$BTDFSettingsFile.old"
Get-Content -Path "$BTDFSettingsFile.old" | ForEach-Object {
$line = $_
$hashConfig.GetEnumerator() | ForEach-Object {
if ($line -match $_.Key)
{
$line = $line -replace $_.Key, $_.Value
}
}
$line
} | Set-Content -Path $BTDFSettingsFile
Write-Host "DeployToDatabase = $DeployToDatabase"
Write-Host "InstallDirectory = $InstallDirectory"
Write-Host "SkipUndeploy = $SkipUndeploy"
Write-Host "LogFileName = $LogFileName"
Write-Host "MSBuildPath = $MSBuildPath"
Write-Host "PackagePath = $PackagePath"
Write-Host "BTDFSettingsFile = $BTDFSettingsFile"
&$MSBuildPath "/p:DeployBizTalkMgmtDB=$DeployToDatabase;Configuration=Server;SkipUndeploy=$SkipUndeploy" /target:Deploy "/l:FileLogger,Microsoft.Build.Engine;logfile=$LogFileName" "$InstallDirectory\Deployment\Deployment.btdfproj" "/p:ENV_SETTINGS=$BTDFSettingsFile"
}