Last active
March 28, 2018 00:02
-
-
Save tostka/09ea8fbc73067337c50c80db5f8f5256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# This gist is TRIMMED to just the core pieces #> | |
#*------v Function Test-Port() v------ | |
function Test-Port { | |
# attempt to open a port (telnet xxx.yyy.zzz nnn) | |
# call: Test-Port $server $port | |
PARAM([parameter(Mandatory=$true)] [alias("s")] [string]$Server, [parameter(Mandatory=$true)][alias("p")] | |
[int]$port | |
) ; | |
$ErrorActionPreference = “SilentlyContinue” ; | |
$socket = new-object Net.Sockets.TcpClient ; | |
$socket.Connect($Server, $port) ; | |
if ($socket.Connected) { | |
write-verbose -verbose:$true "Successful connection to $($Server):$($port)" | |
$socket.Close() | |
return $True; | |
} else { | |
write-verbose -verbose:$true "Failed to connect to $($Server):$($port)" | |
return $False; | |
} # if-block end | |
$socket = $null | |
}#*------^ END Function Test-Port() ^------ | |
#*======v SUB MAIN v====== | |
$tsrvr=read-host -prompt "Server to be pinged until RDP available" ; | |
Do {write-host "." -NoNewLine;Start-Sleep -m (1000 * 5)} Until ((test-port $tsrvr 3389)) ; | |
write-host "`a" ; # beep | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):Launching rdp to $($tsrvr)..." ; | |
mstsc.exe /v:$($tsrvr) ; | |
#*======^ END SUB MAIN ^====== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment