Phidiax Tech Blog

Adventures in custom software and technology implementation.

BizTalk Server 2016: Auto-Install Script for SFTP Requirement of WinSCP

Background

In the BizTalk installation documentation it outlines the fact that you need WinSCP. Michael Stephenson wrote a great article that goes into the how and why. He also included a simple script to automatically install the right version.

Solution

As I love to script, I wanted to build something that was a little more robust and flexible. Here is the extended script which tries to figure out as much as possible automatically and gives error messages that might help you track down the problem.

#Parameters
Param([Parameter(Mandatory=$true)][string]$downloadNoGetTo)
$Continue = $true
$downloadNoGetToExists = Test-Path $downloadNoGetTo
if (-not $downloadNoGetToExists)
{
    New-Item -Path $downloadNoGetTo -ItemType "Directory"
}
if (-not $downloadNoGetToExists)
{
    $Continue = $false
    Write-Host "An attempt to use the " $downloadNoGetTo " directory for a download target failed"
}
if ($Continue)
{
    $bizTalkInstallFolder = (Get-Item Env:BTSINSTALLPATH).Value
    if (-not $bizTalkInstallFolder)
    {
        $bizTalkInstallFolder = (get-itemPropertyValue 'HKLM:\SOFTWARE\Microsoft\BizTalk Server\3.0' -Name 'InstallPath')
        if (-not $bizTalkInstallFolder)
        {
            $bizTalkInstallFolder = "C:\Program Files (x86)\Microsoft BizTalk Server 2016\\"
        }
    }
    $bizTalkInstallFolderExists = Test-Path $bizTalkInstallFolder
    if (-not $bizTalkInstallFolderExists)
    {
        $Continue = $false
        Write-Host "The BizTalk Installation was not found by inspecting the enviornment or registry."
    }
if ($Continue)
    {
        #Download NuGet
        $sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
        Write-Host “Downloading Nuget from ” $sourceNugetExe
        $targetNugetExe = "$downloadNoGetTo\nuget.exe"
        Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
        $targetNugetExeExists = Test-Path $targetNugetExe
        if (-not $targetNugetExeExists)
        {
            $Continue = $false
            Write-Host "The download of the Nuget EXE from " $sourceNugetExe " did not succeed"
        }
        if ($Continue)
        {
            #Download the right version of WinSCP
            Write-Host "Downloading WinSCP from NuGet " + $sourceNugetExe
            Invoke-Expression "$targetNugetExe Install WinSCP -Version 5.7.7 -OutputDirectory $downloadNoGetTo"
            $WinSCP = "$downloadNoGetTo\WinSCP.5.7.7\content\WinSCP.exe"
            $WinSCPDll = "$downloadNoGetTo\WinSCP.5.7.7\lib\WinSCPnet.dll"
            $WinSCPExists = Test-Path $WinSCP
            $WinSCPDLLExists = Test-Path $WinSCPDll
            if (-not $WinSCPExists -or -not $WinSCPDLLExists)
            {
                $Continue = $false
                Write-Host "WinSCP 5.7.7 was not properly downloaded"
            }
            if ($Continue)
            {
                #Copy WinSCP items to BizTalk Folder
                Write-Host "Copying WinSCP Nuget to BizTalk Folder"
                Copy-Item $WinSCP $bizTalkInstallFolder
                Copy-Item $WinSCPDll $bizTalkInstallFolder
                $WinSCPBTSExists = Test-Path "$bizTalkInstallFolder\WinSCP.exe"
                $WinSCPDLLBTSExists = Test-Path "$biztalkInstallFolder\WinSCPnet.dll"
                if (-not $WinSCPBTSExists)
                {
                    $Continue = $false
                    Write-Host "The WinSCP.exe file was not properly copied to the target folder " $bizTalkInstallFolder
                }
                if (-not $WinSCPDLLBTSExists)
                {
                    $Continue = $false
                    Write-Host "The WinSCPnet.exe file was not properly copied to the target folder " $bizTalkInstallFolder
                }
            }
        }
    }
}
if (-not $Continue)
{
    Write-Host "Something went wrong during installation and the installation is not working"
    Write-Host "Please inspect the errors above and resolve them"
}
else
{
    Write-Host "WinSCP has been properly installed for BizTalk's SFTP Adapter"
}
Loading

Privacy Policy  |  Contact  |  Careers

2009-2017 Phidiax, LLC - All Rights Reserved