Skip to content

Commit a6f7fdb

Browse files
authored
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
1 parent f6b39b0 commit a6f7fdb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

scripts/enable-rdp.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ if((Test-Path variable:islinux) -and $isLinux) {
1515
return
1616
}
1717

18-
# get current IP
19-
$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -like 'ethernet*'}).IPAddress
20-
$port = 3389
21-
2218
# get password or generate
2319
$password = ''
2420
if($env:appveyor_rdp_password) {
@@ -32,7 +28,14 @@ if($env:appveyor_rdp_password) {
3228
$password = [Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", '')
3329
}
3430

31+
$port = 3389
3532
if (-not $nonat) {
33+
if (!(Get-Command "Get-NetIPAddress" -errorAction SilentlyContinue)) {
34+
Write-Warning "NAT translation needs cmdlet 'Get-NetIPAddress', use ps and/or newer VS Image."
35+
return
36+
}
37+
# get current IP
38+
$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -like 'ethernet*'}).IPAddress
3639
if($ip.StartsWith('172.24.')) {
3740
$port = 33800 + ($ip.split('.')[2] - 16) * 256 + $ip.split('.')[3]
3841
} elseif ($ip.StartsWith('192.168.') -or $ip.StartsWith('10.240.')) {

0 commit comments

Comments
 (0)