Author Posts

April 20, 2018 at 10:57 am

Good day.
My PS 5.1 script tests a connection with a SQL Server. The script does it step by step:
1 Ping the server with the Test-Connection
2 Probe if the port is open with the System.Net.TcpClient.Connect()
3 Now, here i would like to know, without sending credential, if it is indeed a SQL Server behind the port. Is it possible?


April 20, 2018 at 11:32 am

If you're checking by name, you could use

$ConnectionString = "data source = server,55272; initial catalog = master; trusted_connection = true;"
$SqlServer = New-Object Microsoft.SqlServer.Management.Smo.Server
$SqlServer.ConnectionContext.ConnectionString = $ConnectionString

April 21, 2018 at 6:25 pm

Good day.
I was thinking more along the line of writing a certain string to the port. Then getting a certain response, which will indicate that there is a high probability that this port is listened to by MS SQL Server.
The connection string in your example contains 55272, is it a port number?
Also, since trusted_connection = true does it mean that the current domain user must have access rights to the sql server?