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 $Properties
I 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-OdbcDsn
It 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.
"Driver={MariaDB ODBC 3.1 Driver}"(or perhaps explicitly pass that as the DriverName argument)