I am developing an application to migrate non-table objects between various databases (across platform and cross versions) and need to be able to create and delete ODBC DSN records on the fly (for security and automation purposes).
I have been researching PowerShell on lots of forums and in the MS docs but have not been able to resolve what is going on with the following.
Thank you both for your advice. I am still seeing the same error with both alternatives but will delve deeper into the formatting and see if I can resolve it.
I will drop the successful code here once it is working.
Example 3: Add and store an ODBC System DSN
PS C:\> $NewDsn = Add-OdbcDsn -Name "MyPayroll" -DriverName "SQL Server Native Client 10.0" -DsnType "System" -SetPropertyValue @("Server=MyServer", "Trusted_Connection=Yes",
"Database=Payroll") -PassThru
This command adds the ODBC System DSNs named MyPayroll that use SQL Server Native Client 10.0 with the specified DSN properties, and then stores the results in the $NewDsn variable. The
command includes the PassThru parameter. Without PassThru, the cmdlet does not return anything.
The only thing that stands out is you are not providing the database (e.g. “Database=Payroll”). It is also indicates that it wants an array, which is a bit odd, but try just adding the database and see if it clears the error up.