Configure ODBC data source as part of SCCM Application Package

Some applications require ODBC data source addition to the device/workstation as part of application package deployment. We can configure ODBC data source as part of SCCM application package deployment using PowerShell. When we create a ODBC entry in a windows OS device, it creates a registry entry in the device. The ODBC registry is saved in path –

\\HOSTNAME\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBC.INI\

NOTE – Depending on the OS and Application are x86 or x64, the registry entry can be found under location:

64 Bit System DSN in 32-Bit ODBC
\\HOSTNAME\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBC.INI\

32-bit or 64-bit DSN entries in 64-bit ODBC 
\\HOSTNAME\HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI

We can add this registry using PowerShell, here is a sample snippet I used to create the System DSN in ODBC.

try {
    Write-Output "Setting up DB connection"
    if ([System.Environment]::Is64BitOperatingSystem)
         {Start-Process cmd.exe "/c C:\Windows\SysWOW64\odbcconf.exe /A {CONFIGSYSDSN `"SQL Server`" `"DSN=Hardcat|Description=HardCat Prod|Server=PRIMNODSQL03| Database=Hardcat|Trusted_Connection=No`"}"}
            else
         {Start-Process cmd.exe "/c C:\Windows\System32\odbcconf.exe /A {CONFIGSYSDSN `"SQL Server`" `"DSN=Hardcat|Description=HardCat Prod|Server=PRIMNODSQL03| Database=Hardcat|Trusted_Connection=No`"}"}
    }
catch {
    Write-Output $_
      }

If you need to delete an ODBC registry entry use the following PowerShell –

Remove-ItemProperty 'HKLM:\SOFTWARE\WOW6432Node\ODBC\ODBC.INI' -Name "HardCat" -Force -ErrorAction SilentlyContinue 

Leave a Reply

Your email address will not be published. Required fields are marked *