Create 32-Bit system ODBC DSN with Powershell

This Powershell script creates a 32-bit system DSN on a 64-bit server. I got tired of manually creating DSNs for my VMware vCenter installations, so I automated the process. The only argument you need to pass to the script is the FQDN or IP address of your SQL server. If you don’t pass any arguments, the script will abort with an error message.

I apologize for the line wraps, but I think its fairly obvious where the breaks are. You can change the $DSNName to be any name that you wish. $DBName is the name of the database on the SQL server. The script assumes the SQL 2008 native client is installed. If you use a different client you will need to modify the script a bit.

## Creates a 32-bit System DSN on 64-bit OS.

$DSNName = “vCenter Server Update Manager”
$DBName = “vCenter Update Manager”

If($args[0] -eq $NULL) { echo “Must specify FQDN or IP of SQL server.”; Exit}



md $HKLMPath1 -ErrorAction silentlycontinue

set-itemproperty -path $HKLMPath1 -name Driver -value “C:WINDOWSSysWOW64sqlncli10.dll”

set-itemproperty -path $HKLMPath1 -name Description -value $DSNName
set-itemproperty -path $HKLMPath1 -name Server -value $args[0]
set-itemproperty -path $HKLMPath1 -name LastUser -value “”
set-itemproperty -path $HKLMPath1 -name Trusted_Connection -value “Yes”
set-itemproperty -path $HKLMPath1 -name Database -value $DBName

## This is required to allow the ODBC connection to show up in the ODBC Administrator application.

md $HKLMPath2 -ErrorAction silentlycontinue

set-itemproperty -path $HKLMPath2 -name “$DSNName” -value “SQL Server Native Client 10.0”

Print Friendly, PDF & Email

Leave a Reply

2 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
2 Comment authors
Bhavesh SharmaAnonymous Recent comment authors
newest oldest most voted
Notify of

How can I use it under VBA using a button on an Access form?


Bhavesh Sharma
Bhavesh Sharma

Powershell v4 users might benefit from this