Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Powershell Error When Creating ODBC

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?

0

Comments

1 comment
Date Votes
  • When it fails, is it returning an error code?

    0