How to test a SQL Connection with PowerShell

2 months ago

By Eric Gregorich

I found this handy article that explains how to test a SQL Connection using PowerShell.

$connectionString = 'Data Source={0};database={1};User ID={2};Password={3}' -f $ServerName,$DatabaseName,$userName,$password
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $connectionString
$sqlConnection.Open()
$sqlConnection.Close()

“How To Quickly Test a SQL Connection with PowerShell -- Microsoft Certified Professional Magazine Online.” 2018. Microsoft Certified Professional Magazine Online. 2018. https://mcpmag.com/articles/2018/12/10/test-sql-connection-with-powershell.aspx.

Spread the word

Keep reading