Published on

Build SQL connection string in powershell

Authors

Problem

Build SQL connection string in powershell

Solution

$Server = "localhost"
$Database = "TestDB"
$UserName = "user"
$Password = "@Passpowrd"
$builder = [System.Data.SqlClient.SqlConnectionStringBuilder]::new()
$builder.Server = $Server
$builder.Database = $Database
$builder.'User ID' = $UserName
$builder.Password = $Password
$result = $builder.ConnectionString
Write-Host "Result: $result"