ODBC/Get-ConnectionStringFromODBC.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

function Join-Parts
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true, Position = 1)] [string] $SystemDSNName
    )

    $settings = Get-Item -Path "HKLM:\SOFTWARE\ODBC\ODBC.INI\$SystemDSNName"
    $connectionString = ""

    foreach($key in $settings.GetValueNames())
    {
        $value = $settings.GetValue($key)
        if(-not [string]::IsNullOrEmpty($value))
        {
            $connectionString += "$key=$value;"
        }
    }

    return $connectionString
}