Powershell function to test if an ODBC connection is able to connect with the database or not.  The function returns $true if a successful connection is made, and $false if it cannot connect. It will print an error message to the console if there is an error somewhere, like the ODBC connection do not exist.


Source code:

Function Test-ODBCConnection { 
                    HelpMessage="DSN name of ODBC connection")] 
    $conn = new-object system.data.odbc.odbcconnection 
    $conn.connectionstring = "(DSN=$DSN)" 
    try { 
        if (($conn.open()) -eq $true) { 
        else { 
    } catch { 
        Write-Host $_.Exception.Message 
For more documentation on this script, please see my blog at: https://www.andersrodland.com