Import-module D:\PathToNPGSql\Npgsql.dll
$conn = [Npgsql.NpgsqlConnection]::new()
$conn.ConnectionString = 'Server=localhost;Username=postgres;Password=123;Database=postgres;CommandTimeout=300;Timeout=300'
$conn.Open()
$cmd = new-object Npgsql.NpgsqlCommand "(SELECT current_setting('server_version')) UNION ALL (SELECT datname FROM pg_database WHERE datistemplate = false);"
$cmd.Connection = $conn
$r = $cmd.ExecuteReader()
while ($r.Read()) { $r[0] }
$r.Close()
$conn.Close()
https://learn-powershell.net/