commands

^

Test-DbaConnection

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows only

 

Synopsis

Tests the connection to a single instance.

Description

Tests the ability to connect to an SQL Server instance outputting information about the server and instance.

Syntax

Test-DbaConnection
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-Credential] <PSCredential>]
    [[-SqlCredential] <PSCredential>]
    [-SkipPSRemoting]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Test-DbaConnection SQL2016

ComputerName : SQL2016
InstanceName : MSSQLSERVER
SqlInstance : sql2016
SqlVersion : 13.0.4001
ConnectingAsUser : BASE\ctrlb
ConnectSuccess : True
AuthType : Windows Authentication
AuthScheme : KERBEROS
TcpPort : 1433
IPAddress : 10.2.1.5
NetBiosName : sql2016.base.local
IsPingable : True
PSRemotingAccessible : True
DomainName : base.local
LocalWindows : 10.0.15063.0
LocalPowerShell : 5.1.15063.502
LocalCLR : 4.0.30319.42000
LocalSMOVersion : 13.0.0.0
LocalDomainUser : True
LocalRunAsAdmin : False
LocalEdition : Desktop
Test connection to SQL2016 and outputs information collected

Example: 2
PS C:\> $winCred = Get-Credential sql2017\Administrator
PS C:\> $sqlCred = Get-Credential sa
PS C:\> Test-DbaConnection SQL2017 -SqlCredential $sqlCred -Credential $winCred

ComputerName : SQL2017
InstanceName : MSSQLSERVER
SqlInstance : sql2017
SqlVersion : 14.0.3356
ConnectingAsUser : sa
ConnectSuccess : True
AuthType : SQL Authentication
AuthScheme : SQL
TcpPort : 50164
IPAddress : 10.10.10.15
NetBiosName : sql2017.company.local
IsPingable : True
PSRemotingAccessible : True
DomainName : company.local
LocalWindows : 10.0.15063.0
LocalPowerShell : 5.1.19041.610
LocalCLR : 4.0.30319.42000
LocalSMOVersion : 15.100.0.0
LocalDomainUser : True
LocalRunAsAdmin : False
LocalEdition : Desktop
Test connection to SQL2017 instance and collecting information on SQL Server using the sa login, local Administrator account is used to collect port information

Optional Parameters

-SqlInstance

The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances.

Alias
Required False
Pipeline true (ByValue)
Default Value
-Credential

Credential object used to connect to the Computer as a different user. Utilized for gathering PSRemoting and TCPPort information.

Alias
Required False
Pipeline false
Default Value
-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential). Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported. For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-SkipPSRemoting

This switch will skip the test for PSRemoting.

Alias
Required False
Pipeline false
Default Value False
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message. This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting. Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False

 

Want to see the source code for this command? Check out Test-DbaConnection on GitHub.
Want to see the Bill Of Health for this command? Check out Test-DbaConnection.