SSH from Windows to Open VMS using PS

We currently employ an application called Automate. Certain jobs need an open connection to VMS via Telnet. I’ve been told Telnet is a security risk and switch to SSH. I found and modified the following PS script years ago. Would anyone be able to help with a conversion from Telnet to SSH using this script?
Thanks.

function readtelnet {
  $response = ""
  While($Stream.DataAvailable) {
    $Read = $Stream.Read($Buffer, 0, 1024)
    $response += ($Encoding.GetString($Buffer, 0, $Read))
  }
  return $response;
}

function waitfor {
  param([string]$search, [int]$timeout)
  if ($timeout -eq 0) {
    $timeout = 3
  }
  $pause = 100
  $pending = readtelnet
  $myResult = $pending
  $counter = 0
  while ($pending -notmatch $search -and $counter -le ($timeout * (1000/$pause))) {
    $counter ++
    Start-Sleep -m $pause
    $pending = readtelnet
    $myResult += $pending
  }
  return $myResult
}

$Socket = New-Object System.Net.Sockets.TcpClient("unfis2", 23)      # Attach to the telnet port on unfas1
if ($Socket) {                                                       # We successfully connected to the server
  $Stream = $Socket.GetStream()
  $Writer = New-Object System.IO.StreamWriter($Stream)
  $Buffer = New-Object System.Byte[] 1024
  $Encoding = New-Object System.Text.AsciiEncoding

  $Result = waitfor 'Username:'
  $Writer.WriteLine('vmsjob_mon')
  $Writer.Flush()
  $Result += waitfor 'Password:'
  $Writer.WriteLine('something')
  $Writer.Flush()
  $Result += waitfor 'UNFAS1_A_\$ ' 30
  $Writer.Flush()
  #$Result= ""
  $Writer.WriteLine('sh sys/owner=production/cluster')
  $Writer.Flush()
  $Result = waitfor 'UNFIS1_A_\$ '
  $Writer.WriteLine('lo')
  $Writer.Flush()
  Start-Sleep -s 1
  #$Result += readtelnet
  readtelnet
} Else {
  $Result = "Unable to connect to host: unfis1:23"
}
  $Result | Out-File "D:\noc\Production\files\RunningJobs.txt"

Just throwing this out there as I have no way to test… what happens if you simply change the port to SSH?

$Socket = New-Object System.Net.Sockets.TcpClient("unfis2", 22)

I suspect you will have certificate validation the first time so that will muck things up.