Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
124 lines (105 sloc) 4.73 KB
<#
File : ExportApplications.ps1
Author : Abid Nasim.
Date : February 18, 2017
Usage : .\ExportApplications.ps1 [-server <server>] [-database <database>] [-logfile <logfile>]
[-logDir <logdir>] [-msiDir <msidir>] [-searchApps <starting application name>]
Example: .\ExportApplications.ps1 -searchApps GS # exports applications begining with GS like GSfoo, GSbar
© Generalsoft Corporation, 2017.
Distributed "as is" with no expressed or implied warranty nor direct or contingent liability whatsoever, even if defects exist, known or unknown
Under MIT License. (see LICENSE in the top folder).
#>
Param(
[string]$server = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\BizTalk Server\3.0\Administration' 'MgmtDBServer').MgmtDBServer,
[string]$database = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\BizTalk Server\3.0\Administration' 'MgmtDBName').MgmtDBName,
[string]$btsHome = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\BizTalk Server\3.0' 'InstallPath').InstallPath,
[string]$btsTask = (join-path -path $btsHome -ChildPath "btsTask.EXE"),
[string]$logDir = $env:TEMP,
[string]$logFile = "apps-$server.txt",
[string]$msiDir = "$logDir\$SERVER",
[string]$searchApps= ""
)
$errorActionPreference="stop"
Write-Host "Starting ...." -ForegroundColor Gray
$elevated = ((whoami /all | select-string S-1-16-12288) -ne $null)
if (!$elevated)
{
Write-Host "You must run this script in elevated mode with Admin rights" -ForegroundColor Yellow -BackgroundColor Red
exit
}
if (!(Test-Path -path $btsTask))
{
Write-Host "Unable to locate BTSTASK.EXE. " -ForegroundColor Yellow -BackgroundColor Red
exit
}
if (!(Test-Path -path $logDir))
{
New-Item -path $logDir -ItemType Directory
}
if (!(Test-Path -path $msiDir))
{
New-Item -path $msiDir -ItemType Directory
}
$regex = "\* Application: -ApplicationName=""(?<name>.*)"" -Description=.*"
&$btsTask -Server:$server -database:$database ListApps | Out-File -FilePath "$logDir\$logFile"
if ($LASTEXITCODE -eq 0 -and (Test-Path -path "$logDir\$logFile" -PathType Leaf))
{
Write-Host -ForegroundColor green "List of Applications generated: $logDir\$logFile"
}
else
{
Write-Host -ForegroundColor red "Failure generating applications. "
exit
}
Select-String $regex "$logDir\$logFile" |
ForEach {
ForEach($match in $_.Matches)
{
$name = $match.Groups["name"].Value
if ($name -eq "BizTalk.System")
{
continue
}
if ($name.StartsWith($searchApps))
{
$xmlFile = "$msiDir\$name-Resource.xml"
&$btsTask ListApp -ApplicationName:$name -ResourceSpec:$xmlFile -Server:$server -Database:$database | Out-Null
if ($LASTEXITCODE -eq 0)
{
Write-Host -ForegroundColor green "Application $name listed in resource file $xmlFile"
}
else
{
Write-Host -ForegroundColor yellow "Failure generating $xmlFile for $name. "
}
&$btsTask ExportApp -ApplicationName:$name -ResourceSpec:$xmlFile -Package:"$msiDir\$name.msi" -Server:$server -Database:$database | Out-File "$msiDir\$name.msi.log"
if ($LASTEXITCODE -eq 0 -and (Test-Path -path "$msiDir\$name.msi" -PathType Leaf))
{
Write-Host -ForegroundColor green "$name exported as $msiDir\$name.msi"
if (!(Test-Path -path "$msiDir\$name.msi.log" -PathType Leaf))
{
Write-Host -ForegroundColor yellow "unable to produce log $msiDir\$name.msi.log"
}
}
else
{
Write-Host -ForegroundColor yellow "Could not export $name"
}
&$btsTask ExportBindings -ApplicationName:$name -Destination:"$msiDir\$name.xml" -Server:$server -Database:$database | Out-File "$msiDir\$name.xml.log"
if ($LASTEXITCODE -eq 0 -and (Test-Path -path "$msiDir\$name.xml" -PathType Leaf))
{
Write-Host -ForegroundColor green "Bindings for $name exported as $msiDir\$name.xml"
if (!(Test-Path -path "$msiDir\$name.xml.log" -PathType Leaf))
{
Write-Host -ForegroundColor yellow "unable to produce log $msiDir\$name.xml.log"
}
}
else
{
Write-Host -ForegroundColor yellow "Could not export bindings for $name"
}
Remove-Item $xmlFile
}
}
}
Write-Host "Done ...." -ForegroundColor Gray