$SshKey = "C:\Users\Administrator\.ssh\id_rsa_tokyo" $VpsHost = "158.179.179.29" function Invoke-RemoteSql([string]$sql) { $b64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($sql)) $remoteCmd = "echo '$b64' | base64 -d > /tmp/run_query.sql && sudo -u postgres psql -d classnotify -t -A -F '|' -f /tmp/run_query.sql 2>&1 && rm -f /tmp/run_query.sql" $out = ssh -i $SshKey -o StrictHostKeyChecking=no -o ConnectTimeout=15 -o BatchMode=yes root@$VpsHost $remoteCmd if ($out) { return ($out -join "`n").Trim() } return "" } $res = Invoke-RemoteSql 'SELECT "Id", "LicensedUntil", "LicenseTier", NOW() as "CurrentNow" FROM "Devices" WHERE "Id" = ''dev_e059ad69f1064480'';' Write-Host "Device info in DB:" Write-Host $res