@@ -69,15 +69,15 @@ Write-Host "Establishing link to $ServerName." -ForegroundColor DarkYellow
6969Write-Host " "
7070
7171# Prompt user for which tunnels to open
72- $rdpResponse = Read-Host " Would you like to open the RDP tunnel? (yes/y/ no)"
73- $ftpResponse = Read-Host " Would you like to open the FTP tunnel? (yes/y/ no)"
72+ $rdpResponse = Read-Host " Would you like to open the RDP tunnel? (yes/no)"
73+ $ftpResponse = Read-Host " Would you like to open the FTP tunnel? (yes/no)"
7474
7575# Build SSH command based on user responses
7676$sshCommand = " ssh -p $port $user @$ip -N"
77- if ($rdpResponse -eq " yes " -or $rdpResponse -eq " y" ) {
77+ if ($rdpResponse.Substring ( 0 , 1 ).ToLower() -eq " y" ) {
7878 $sshCommand += " -L ${RDP1} :${h1} :${h1p} "
7979}
80- if ($ftpResponse -eq " yes " -or $ftpResponse -eq " y" ) {
80+ if ($ftpResponse.Substring ( 0 , 1 ).ToLower() -eq " y" ) {
8181 $sshCommand += " -L ${FTP1} :${h1} :${h2p} "
8282}
8383$sshCommand += " -i $keyPath "
@@ -98,17 +98,17 @@ $connectedRDP = $false
9898$connectedFTP = $false
9999$startTime = Get-Date
100100
101- while ((-not $connectedRDP -and ( $rdpResponse -eq " yes " -or $rdpResponse - eq " y" )) -or (-not $connectedFTP -and ( $ftpResponse -eq " yes " -or $ftpResponse - eq " y" ) ) -and (New-TimeSpan - Start $startTime - End (Get-Date )).TotalSeconds -lt $timeout ) {
102- if ($rdpResponse -eq " yes " -or $rdpResponse -eq " y" ) {
101+ while ((-not $connectedRDP -and $rdpResponse.Substring ( 0 , 1 ).ToLower() - eq " y" ) -or (-not $connectedFTP -and $ftpResponse.Substring ( 0 , 1 ).ToLower() - eq " y" ) -and (New-TimeSpan - Start $startTime - End (Get-Date )).TotalSeconds -lt $timeout ) {
102+ if ($rdpResponse.Substring ( 0 , 1 ).ToLower() -eq " y" ) {
103103 $connectedRDP = Test-NetConnection - ComputerName $h1 - Port $RDP1 - WarningAction SilentlyContinue | Select-Object - ExpandProperty TcpTestSucceeded
104104 }
105- if ($ftpResponse -eq " yes " -or $ftpResponse -eq " y" ) {
105+ if ($ftpResponse.Substring ( 0 , 1 ).ToLower() -eq " y" ) {
106106 $connectedFTP = Test-NetConnection - ComputerName $h1 - Port $FTP1 - WarningAction SilentlyContinue | Select-Object - ExpandProperty TcpTestSucceeded
107107 }
108108 Start-Sleep - Seconds 1
109109}
110110
111- if ((-not $connectedRDP -and ( $rdpResponse -eq " yes " -or $rdpResponse - eq " y" )) -or (-not $connectedFTP -and ( $ftpResponse -eq " yes " -or $ftpResponse - eq " y" ) )) {
111+ if ((-not $connectedRDP -and $rdpResponse.Substring ( 0 , 1 ).ToLower() - eq " y" ) -or (-not $connectedFTP -and $ftpResponse.Substring ( 0 , 1 ).ToLower() - eq " y" )) {
112112 Write-Host " "
113113 Write-Host " Connection could not be established within $timeout seconds." - ForegroundColor Red
114114 Write-Host " Your link to the $CompanyName servers has not been established." - ForegroundColor Red
@@ -125,12 +125,12 @@ Write-Host "If the remote connection doesn't automatically open and" -Foreground
125125Write-Host " start connecting, Use the below Details to connect to" - ForegroundColor Blue
126126Write-Host " the relevant services:" - ForegroundColor Blue
127127Write-Host " ---------------------------------------------------------" - ForegroundColor Blue
128- if ($rdpResponse -eq " yes " -or $rdpResponse -eq " y" ) {
128+ if ($rdpResponse.Substring ( 0 , 1 ).ToLower() -eq " y" ) {
129129 Write-Host " Remote Desktop Connection:" - ForegroundColor Blue
130130 Write-Host " IP: $h1 " - ForegroundColor Blue
131131 Write-Host " Port: $RDP1 " - ForegroundColor Blue
132132}
133- if ($ftpResponse -eq " yes " -or $ftpResponse -eq " y" ) {
133+ if ($ftpResponse.Substring ( 0 , 1 ).ToLower() -eq " y" ) {
134134 Write-Host " FTP:" - ForegroundColor Blue
135135 Write-Host " IP: $h1 " - ForegroundColor Blue
136136 Write-Host " Port: $FTP1 " - ForegroundColor Blue
@@ -140,9 +140,9 @@ Write-Host "---------------------------------------------------------" -Foregrou
140140Write-Host " " - ForegroundColor Blue
141141
142142# Ask the user if they want to open the remote desktop connection
143- if ($rdpResponse -eq " yes " -or $rdpResponse -eq " y" ) {
144- $openRDP = Read-Host " Would you like to open the remote desktop connection now? (yes/y/ no)"
145- if ($openRDP -eq " yes " -or $openRDP -eq " y" ) {
143+ if ($rdpResponse.Substring ( 0 , 1 ).ToLower() -eq " y" ) {
144+ $openRDP = Read-Host " Would you like to open the remote desktop connection now? (yes/no)"
145+ if ($openRDP.Substring ( 0 , 1 ).ToLower() -eq " y" ) {
146146 Write-Host " Opening remote desktop connection window" - ForegroundColor DarkYellow
147147 # Open RDP window
148148 Start-Process mstsc ' connection.rdp'
0 commit comments