From a6f7fdb58ef7fff9457d644840bb332c280151e7 Mon Sep 17 00:00:00 2001 From: Simon Sobisch Date: Mon, 23 Aug 2021 19:56:11 +0200 Subject: [PATCH] remove IP lookup for nonat, check for Get-NetIPAddress cmdlet (#3692) * remove IP lookup for nonat possibly fixing #3691 * Update enable-rdp.ps1 fixing #3691 --- scripts/enable-rdp.ps1 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/enable-rdp.ps1 b/scripts/enable-rdp.ps1 index 560a572..6bbdb1c 100644 --- a/scripts/enable-rdp.ps1 +++ b/scripts/enable-rdp.ps1 @@ -15,10 +15,6 @@ if((Test-Path variable:islinux) -and $isLinux) { return } -# get current IP -$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -like 'ethernet*'}).IPAddress -$port = 3389 - # get password or generate $password = '' if($env:appveyor_rdp_password) { @@ -32,7 +28,14 @@ if($env:appveyor_rdp_password) { $password = [Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", '') } +$port = 3389 if (-not $nonat) { + if (!(Get-Command "Get-NetIPAddress" -errorAction SilentlyContinue)) { + Write-Warning "NAT translation needs cmdlet 'Get-NetIPAddress', use ps and/or newer VS Image." + return + } + # get current IP + $ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -like 'ethernet*'}).IPAddress if($ip.StartsWith('172.24.')) { $port = 33800 + ($ip.split('.')[2] - 16) * 256 + $ip.split('.')[3] } elseif ($ip.StartsWith('192.168.') -or $ip.StartsWith('10.240.')) {