25 January 2016

Fix for A connection to the deployment could not be made

This error is very annoying when running through a build. I Googled and found this fix to it by Kyle Beckman. The trick is delaying the LiteTouch.wsf from trying to execute the next task before network connectivity is available. Kyle's fix is putting a simple timed delay in the LiteTouch.wsf. I decided to enhance this fix by using PowerShell. Instead of having to guess at how long to wait, why not use the Test-Connection commandlet and delay the script until connectivity is available? That is what I did and it has worked perfectly. The first thing was to create the oShell object. Next use oShell.run to execute the powershell command. I used the -command so that it did not have to execute and external script. You will also need to customize the part that says <IP or DNS Address>. I use the fully qualified domain name of our DNS server to test for network connectivity. You can see the code I added in the field below:


           Set oShell = CreateObject("Wscript.shell")  
           oShell.run("powershell.exe -executionpolicy bypass -command Do {$Connectivity = Test-Connection -Destination <IP or DNS Address> -Count 1 -Quiet} while ($Connectivity -eq $false)")  
   

This is what the code looks like as a whole within the LiteTouch.wsf file:

      Function ValidateDeployRootWithRecovery  
   
           Dim sARF  
           Dim sNetworkErrorHint  
           DIm iRetVal  
           Dim sLTISuspend  
   
           'Wait for network connectivity  
           Set oShell = CreateObject("Wscript.shell")  
           oShell.run("powershell.exe -executionpolicy bypass -command Do {$Connectivity = Test-Connection -Destination <IP or DNS Address> -Count 1 -Quiet} while ($Connectivity -eq $false)")  
           If oUtility.ValidateConnectionEx(oEnvironment.Item("DeployRoot"), True) = Success then  
                ValidateDeployRootWithRecovery = SUCCESS  
                exit function  
           End if  
   


NOTE: This will require at least PowerShell version 3. Also, I would highly recommend making a copy of LiteTouch.wsf before making any modifications to it. 

0 comments:

Post a Comment