@@ -655,18 +655,24 @@ while ($runCount -le $NumberOfIterations)
655655 if (($pubVMObject = Get-AzureRmVM - ResourceGroupName $CanaryVMRG - Name $publicVMName - ErrorAction Stop) -and ($pvtVMObject = Get-AzureRmVM - ResourceGroupName $CanaryVMRG - Name $privateVMName - ErrorAction Stop))
656656 {
657657 Set-item wsman:\localhost\Client\TrustedHosts - Value $publicVMIP - Force - Confirm:$false
658- if ($publicVMSession = New-PSSession - ComputerName $publicVMIP - Credential $vmCreds - ErrorAction Stop)
658+ $sw = [system.diagnostics.stopwatch ]::startNew()
659+ while (-not ($publicVMSession = New-PSSession - ComputerName $publicVMIP - Credential $vmCreds - ErrorAction SilentlyContinue)){if (($sw.ElapsedMilliseconds -gt 240000 ) -and (-not ($publicVMSession ))){$sw.Stop (); throw [System.Exception ]" Unable to establish a remote session to the tenant VM using public IP: $publicVMIP " }; Start-Sleep - Seconds 15 }
660+ if ($publicVMSession )
659661 {
660662 Invoke-Command - Session $publicVMSession - Script{param ($privateIP ) Set-item wsman:\localhost\Client\TrustedHosts - Value $privateIP - Force - Confirm:$false } - ArgumentList $privateVMIP | Out-Null
661- $privateVMResponseFromRemoteSession = Invoke-Command - Session $publicVMSession - Script{param ($privateIP , $vmCreds , $scriptToRun ) $privateSess = New-PSSession - ComputerName $privateIP - Credential $vmCreds ; Invoke-Command - Session $privateSess - Script{param ($script ) Invoke-Expression $script } - ArgumentList $scriptToRun } - ArgumentList $privateVMIP , $vmCreds , $vmCommsScriptBlock
663+ $privateVMResponseFromRemoteSession = Invoke-Command - Session $publicVMSession - Script{param ($privateIP , $vmCreds , $scriptToRun ) $sw = [system.diagnostics.stopwatch ]::startNew(); while (-not ($privateSess = New-PSSession - ComputerName $privateIP - Credential $vmCreds - ErrorAction SilentlyContinue)){if (($sw.ElapsedMilliseconds -gt 240000 ) -and (-not ($privateSess ))){$sw.Stop (); throw [System.Exception ]" Unable to establish a remote session to the tenant VM using private IP: $privateIP " }; Start-Sleep - Seconds 15 }; Invoke-Command - Session $privateSess - Script{param ($script ) Invoke-Expression $script } - ArgumentList $scriptToRun } - ArgumentList $privateVMIP , $vmCreds , $vmCommsScriptBlock - ErrorVariable remoteExecError 2> $null
664+ $publicVMSession | Remove-PSSession - Confirm:$false
665+ if ($remoteExecError )
666+ {
667+ throw [System.Exception ]" $remoteExecError "
668+ }
662669 if ($privateVMResponseFromRemoteSession )
663670 {
664- $publicVMSession | Remove-PSSession - Confirm:$false
665671 $privateVMResponseFromRemoteSession
666672 }
667673 else
668674 {
669- throw [System.Exception ]" Public VM was not able to talk to the Private VM via the private IP"
675+ throw [System.Exception ]" The expected certificate from KV was not found on the tenant VM with private IP: $privateVMIP "
670676 }
671677 }
672678 }
@@ -803,18 +809,24 @@ while ($runCount -le $NumberOfIterations)
803809 if (($pubVMObject = Get-AzureRmVM - ResourceGroupName $CanaryVMRG - Name $publicVMName - ErrorAction Stop) -and ($pvtVMObject = Get-AzureRmVM - ResourceGroupName $CanaryVMRG - Name $privateVMName - ErrorAction Stop))
804810 {
805811 Set-item wsman:\localhost\Client\TrustedHosts - Value $publicVMIP - Force - Confirm:$false
806- if ($publicVMSession = New-PSSession - ComputerName $publicVMIP - Credential $vmCreds - ErrorAction Stop)
812+ $sw = [system.diagnostics.stopwatch ]::startNew()
813+ while (-not ($publicVMSession = New-PSSession - ComputerName $publicVMIP - Credential $vmCreds - ErrorAction SilentlyContinue)){if (($sw.ElapsedMilliseconds -gt 240000 ) -and (-not ($publicVMSession ))){$sw.Stop (); throw [System.Exception ]" Unable to establish a remote session to the tenant VM using public IP: $publicVMIP " }; Start-Sleep - Seconds 15 }
814+ if ($publicVMSession )
807815 {
808816 Invoke-Command - Session $publicVMSession - Script{param ($privateIP ) Set-item wsman:\localhost\Client\TrustedHosts - Value $privateIP - Force - Confirm:$false } - ArgumentList $privateVMIP | Out-Null
809- $privateVMResponseFromRemoteSession = Invoke-Command - Session $publicVMSession - Script{param ($privateIP , $vmCreds , $scriptToRun ) $privateSess = New-PSSession - ComputerName $privateIP - Credential $vmCreds ; Invoke-Command - Session $privateSess - Script{param ($script ) Invoke-Expression $script } - ArgumentList $scriptToRun } - ArgumentList $privateVMIP , $vmCreds , $vmCommsScriptBlock
817+ $privateVMResponseFromRemoteSession = Invoke-Command - Session $publicVMSession - Script{param ($privateIP , $vmCreds , $scriptToRun ) $sw = [system.diagnostics.stopwatch ]::startNew(); while (-not ($privateSess = New-PSSession - ComputerName $privateIP - Credential $vmCreds - ErrorAction SilentlyContinue)){if (($sw.ElapsedMilliseconds -gt 240000 ) -and (-not ($privateSess ))){$sw.Stop (); throw [System.Exception ]" Unable to establish a remote session to the tenant VM using private IP: $privateIP " }; Start-Sleep - Seconds 15 }; Invoke-Command - Session $privateSess - Script{param ($script ) Invoke-Expression $script } - ArgumentList $scriptToRun } - ArgumentList $privateVMIP , $vmCreds , $vmCommsScriptBlock - ErrorVariable remoteExecError 2> $null
818+ $publicVMSession | Remove-PSSession - Confirm:$false
819+ if ($remoteExecError )
820+ {
821+ throw [System.Exception ]" $remoteExecError "
822+ }
810823 if ($privateVMResponseFromRemoteSession )
811824 {
812- $publicVMSession | Remove-PSSession - Confirm:$false
813825 $privateVMResponseFromRemoteSession
814826 }
815827 else
816828 {
817- throw [System.Exception ]" Public VM was not able to talk to the Private VM via the private IP"
829+ throw [System.Exception ]" Host name could not be retrieved from the tenant VM with private IP: $privateVMIP "
818830 }
819831 }
820832 }
0 commit comments