Powershell Error When Creating ODBC

0

I have a program that needs a ODBC connection created but it wont happen when installing via PDQ until I worked out how to create the step. Well I figured out the step but I need to test is it was already created and if not create it and then run the installs. This is what I have for the PS.

    If (Get-OdbcDsn -Name namehere) {
} Else {Add-OdbcDsn -Name "namehere" -DriverName "SQL Server" -DsnType System -Platform '32-bit' -SetPropertyValue @("Server=server\instance", "Trusted_Connection=Yes", "Database=dbname")
}

I have real values for namehere, server\instance and dbname

The above scripts works in that if its already created, it does nothing and gives a status of successful. If not already created it will create the odbc but gives a status of failed.

Why?

Cancel
login to comment
0

When it fails, is it returning an error code?

Cancel
login to comment

Reply