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.
- How do I create a DSN using CIM/WMI for drivers with names containing wildcard characters?
- Is there a way to refer to a driver whose name contains
*
in a manner that allows theAdd
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