Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (50 sloc) 1.58 KB
FUNCTION Test-SqlConnection {
Test connection to SQL Instance
Test connection to SQL Instance
The name of the instance you wish to check connections to
PS C:\> Test-SQLConnection -Instance DEV-MSSQL
Author : Ryan DeVries
Last Updated: 2015/06/01
Version : 1
[Parameter(Position=0,Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName,HelpMessage="The name of the instance")]
begin {
Write-Verbose "Detected parameter set $($PSCmdlet.ParameterSetName)"
$scriptstring = "Starting $($MyInvocation.MyCommand)"
foreach ($param in $PSBoundParameters.GetEnumerator()){ $scriptstring += " -$($param.key) $($param.value)"}
Write-Verbose $scriptstring
process {
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $instance
$srv.ConnectionContext.ConnectTimeout = 5
try {
Write-Verbose "Trying to connect to $instance"
# Try and connect to server
Write-Verbose "Connection successful! Disconnecting from $instance"
return $true
catch {
Write-Verbose "Could not connect to $instance"
return $false
end { Write-Verbose "Ending $($MyInvocation.Mycommand)" }