Sytone's Ramblings

The occasional posts of a guy who plays with technology.

Using SqlConnectionStringBuilder in PowerShell

2010-10-12 1 min read General

I wanted to use the SqlConnectionStringBuilder object in the SqlClient area but was having issues accessing the properties. The Object itself is just a collection with a key value structure.

To access the keys use the following PowerShell code:

$builder = New-Object System.Data.SqlClient.SqlConnectionStringBuilder
$builder.Keys

To set a property just use the key as a reference. For example:

$builder["Data Source"] = $server
$builder["Initial Catalog"] = $database
$builder["Encrypt"] = $true
$builder["TrustServerCertificate"] = $false
$builder["User ID"] = $login
$builder["Password"] = $password