I'm trying to configure a MariaDB ODBC DSN automatically in PowerShell
my code so far is this:
$DriverName = (Get-OdbcDriver -Name "MariaDB*" | Where-Object Platform -eq "64-bit").Name# Setting up $dsn, $server, $port, $user, $pwd and $db$Properties = @("SERVER=$server", "PORT=$port", "USER=$user", "PASSWORD=$pwd", "DATABASE=$db")Add-OdbcDsn -Name $DSNName -DriverName $DriverName -DsnType "User" -Platform "64-bit" -SetPropertyValue $PropertiesI keep getting the error
Add-OdbcDsn : Driver's ConfigDSN, ConfigDriver, or ConfigTranslator failed (Installer error code: 11).+ Add-OdbcDsn -Name $DSNName -DriverName $DriverName -DsnType "User ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (... ODBC User DSN):Root/Microsoft/...SFT_OdbcDsnTask) [Add -OdbcDsn], CimException + FullyQualifiedErrorId : MI RESULT 0,Add-OdbcDsnIt seems to be some missing field in $properties, but I can't figure out which one I'm missing
Thanks
Edit to add: I'm using the ODBC driver MariaDB ODBC 3.1 Driver, on windows 11
Edit #2: I made sure that $DriverName gives me only one value.
Also, as someone mentionned, I tried adding the option UID=$user and PWD=$pwd but it gave me the error
Add-OdbcDsn : Attempt to set the {UID or PWD} key of a DSN. These keys should not be stored in the registry for security reason. Provide the credential information at runtime via SQLDriverConnect, SQLConnect or SQLBrowseConnect.- Thedocumentation appears to suggest you need to include
"Driver={MariaDB ODBC 3.1 Driver}"(or perhaps explicitly pass that as the DriverName argument)Mathias R. Jessen– Mathias R. Jessen2025-07-25 16:55:04 +00:00CommentedJul 25 at 16:55 - 1@MathiasR.Jessen isn't it what the option -DriverName $DriverName do ?gee3107– gee31072025-07-25 20:08:21 +00:00CommentedJul 25 at 20:08
- You only need to use Add-OdbcDsn once on a machine or manually add the entry into the computer. From start button type : ODBC Data Source. See if odbc is already added to you machine.jdweng– jdweng2025-07-25 21:21:51 +00:00CommentedJul 25 at 21:21
- 1@jdweng Yes I know how to use ODBC Data Sources. I wan to do it in a script because I will need to give that script to people without needing them to manually configure itgee3107– gee31072025-07-26 00:33:08 +00:00CommentedJul 26 at 0:33
- 1@gee3107 yes, but we don't know how many versions of the driver is installed on the machine - you may be passing the name of multiple driversMathias R. Jessen– Mathias R. Jessen2025-07-26 09:47:13 +00:00CommentedJul 26 at 9:47
Related questions
Related questions