install-postgresql-odbc.ps1 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Function Install-PostgresODBC() {
  2. . .\resources\get-cpu.ps1
  3. . .\resources\get-link.ps1
  4. . .\resources\get-file.ps1
  5. . .\resources\expand-zip.ps1
  6. . .\resources\get-database_password
  7. if (Get-Installed-App "psqlODBC*") {
  8. Write-Host PostgreSQL ODBC is already installed
  9. return
  10. }
  11. $cpu = Get-CPU
  12. if ($cpu -eq "x86") {
  13. $url = "https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_10_01_0000-x86.zip"
  14. }
  15. else {
  16. $url = "https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_10_01_0000-x64.zip"
  17. }
  18. Write-Host Download ODBC from $url -ForegroundColor Cyan
  19. $filename = Get-File $url -Force
  20. Expand-ZIP $filename
  21. Write-Host Install postgresql-odbc
  22. $filename = Get-Item psqlodbc*.exe
  23. if ($filename) {
  24. Start-Process $filename -Wait
  25. }
  26. $filename = Get-Item psqlodbc*.msi
  27. if ($filename) {
  28. Start-Process msiexec "/i $filename /passive /qb" -Wait
  29. }
  30. #if ((Get-Command Get-OdbcDsn)) { # -ErrorAction SilentlyContinue
  31. #Get or create DSN
  32. # $dsn = Get-OdbcDsn FusionPBX -ErrorAction SilentlyContinue
  33. # Remove-OdbcDsn FusionPBX -DsnType System
  34. # if ($dsn.length -eq 0) {
  35. # Get ODBC Driver name
  36. # $driver = (Get-OdbcDriver -Name "PostgreSQL Unicode*").Name
  37. # $dsn = Add-OdbcDsn -DsnType System -Name fusionpbx -DriverName $driver -SetPropertyValue "servername=localhost","port=5432","database=fusionpbx","GssAuthUseGSS=0"
  38. # }
  39. # $dsn | Set-OdbcDsn -SetPropertyValue Username=postgres
  40. # $dsn | Set-OdbcDsn -SetPropertyValue password=$database_password
  41. #}
  42. #else {
  43. # Configure DSN with ODBC Administrator
  44. Write-Host The ODBC Administrator window will open. -ForegroundColor Yellow
  45. if ($cpu -eq "x86") {
  46. $driver="PostgreSQL Unicode"
  47. }
  48. else {
  49. $driver="PostgreSQL Unicode(x64)"
  50. }
  51. #ODBCCONF.EXE /Lv dsn_log.txt CONFIGSYSDSN "$driver" "DSN=fusionpbx|server=localhost|port=5432|database=fusionpbx|Username=postgres|password=$database_password"
  52. ODBCCONF.EXE /Lv dsn_log.txt CONFIGSYSDSN "$driver" "DSN=fusionpbx|server=localhost|port=5432|database=fusionpbx|Username=postgres|password=$database_password|GssAuthUseGSS=false"
  53. #}
  54. #Start-Process odbcad32.exe -Wait
  55. }
  56. #. .\resources\get-database_password
  57. #Test-ODBC fusionpbx postgres $database_password