Port connection monitor

Port connection monitor

I have a Windows machine with and application that connects to a remote port on an external server. I need to monitor if the connection is Established and be able to alert if it is not. I have attempted writing a PowerShell script for the custom plugin, but I am no expert in that area. I was hoping to return "Connected" when Established and "Disconnected" when down, then set a threshold to alert on down.

Using Telnet as an example, I was attempting to perform the following: 

Function Get-Data
    $Telnet = (Get-NetTCPConnection -RemoteAddress -RemotePort 23 | select `State)
    if($Telnet = "@{State=Established}")
        {$State = "Connected"}
        {$State = "Disconnected"}
    write-output $State

I found my if else wasn't working; when the connection was truly up, I could run Get-Data and it would return "Connected". When I severed the connection, I received the "No matching MSFT_NetTCPConnection... followed by "Connected"

Has anybody needed to perform something similar? I also thought about checking for established ports via process, but I would be in the same boat...not know how to return the correct information in the plugin script.