Skip to content

Instantly share code, notes, and snippets.

@Eason0210
Forked from MasFlam/run-psql.ps1
Created June 13, 2023 05:18
Show Gist options
  • Save Eason0210/04f4ba77e617a075a8bd99b87783a70b to your computer and use it in GitHub Desktop.
Save Eason0210/04f4ba77e617a075a8bd99b87783a70b to your computer and use it in GitHub Desktop.
PowerShell script to run psql prompting for connection details
Write-Host "Enter connection details:"
$server = "localhost"
$server_maybe = (Read-Host -Prompt "Server [$server]")
If($server_maybe -ne "") {
$server = $server_maybe
}
$db = "postgres"
$db_maybe = (Read-Host -Prompt "Database [$db]")
If($db_maybe -ne "") {
$db = $db_maybe
}
$port = 5432
[int]$port_maybe = (Read-Host -Prompt "Port [$port]")
If($port_maybe -ne "") {
$port = $port_maybe
}
$username = "postgres"
$username_maybe = (Read-Host -Prompt "Username [$username]")
If($username_maybe -ne "") {
$username = $username_maybe
}
Write-Host "Running psql"
Write-Host
psql -h $server -U $username -d $db -p $port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment