1

Note: I'm aware of the Wdac module but it currently does not work from PowerShell 7. Working around that issue led to this question.


The Add method of the MSFT_OdbcDsnTask class has a required parameter "DriverName" whose description reads as follows:

DriverName [in]

The name of the ODBC driver for the new ODBC DSN. You cannot use wildcard characters.

Most of the ODBC drivers on my computer have names containing * which, I think, is interpreted as a wildcard character in this context. The following are some examples:

  • Microsoft Excel Driver (*.xls)
  • Microsoft Access Driver (*.mdb)
  • Microsoft Access Text Driver (*.txt, *.csv)

Invoking the Add method to create a DSN by invoking the PowerShell command

Invoke-CimMethod -ClassName MSFT_OdbcDsnTask `
                 -Namespace ROOT\Microsoft\Windows\Wdac `
                 -MethodName 'Add' `
                 -Arguments @{
                     Name       = 'test'
                     DsnType    = 'User'
                     Platform   = '32-bit'
                     DriverName = 'Microsoft Excel Driver (*.xls)'
                     # DriverName = 'SQL Server' }

results in the error The requested object could not be found.. Changing the commented line so that DriverName = 'SQL Server' instead of the excel driver that contains the wildcard successfully creates a DSN.

  1. How do I create a DSN using CIM/WMI for drivers with names containing wildcard characters?
  2. Is there a way to refer to a driver whose name contains * in a manner that allows the Add method to find that driver?

Update 1:

The error generated pursuant to this comment got me wondering whether this really was down to wildcards. I ran this script to test all of the drivers mentioned on my computer. The result is below. Note that the driver Microsoft ODBC for Oracle failed with the error The driver {ODBC for Oracle} is not installed..

Result  Name
------  ----
Failure Driver do Microsoft Access (*.mdb)
Failure Microsoft Paradox Driver (*.db )
Failure Microsoft Access Driver (*.mdb)
Failure Microsoft Text-Treiber (*.txt; *.csv)
Failure Microsoft Excel-Treiber (*.xls)
Failure Microsoft Access Text Driver (*.txt, *.csv)
Failure Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)
Failure Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)
Failure Microsoft dBase Driver (*.dbf)
Failure Microsoft Access Driver (*.mdb, *.accdb)
Failure Microsoft ODBC for Oracle
Failure Microsoft Text Driver (*.txt; *.csv)
Failure Driver da Microsoft para arquivos texto (*.txt; *.csv)
Failure Driver do Microsoft Excel(*.xls)
Failure Microsoft Access-Treiber (*.mdb)
Failure Driver do Microsoft Paradox (*.db )
Failure Microsoft Excel Driver (*.xls)
Failure Driver do Microsoft dBase (*.dbf)
Failure Microsoft Paradox-Treiber (*.db )
Failure Microsoft dBase-Treiber (*.dbf)
Success SQL Server Native Client 11.0
Success SQL Server
Success SQL Server
Success SQL Server Native Client 11.0
alx9r
  • 3,675
  • 4
  • 26
  • 55
  • Have you tried escaping the `*` character? `'Microsoft Excel Driver (\*.xls)'` – Theo Apr 26 '20 at 18:33
  • @Theo `'Microsoft Excel Driver (\*.xls)'` results in the error "The driver is not installed." Now I'm wondering whether the wildcard character really is the problem. – alx9r Apr 26 '20 at 20:03
  • Hmmm.. it was a wild guess because I also believed the wildcard character caused the error. I hope you find a solution or someone else knows what causes this. – Theo Apr 26 '20 at 20:52
  • 1
    if this is for ps7, you may want to add that tag to your Question. – Lee_Dailey May 05 '20 at 17:08

0 Answers0