Test if it is indeed a SQL Server behind a port

Welcome Forums General PowerShell Q&A Test if it is indeed a SQL Server behind a port

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
6 months, 3 weeks ago.

  • Author
    Posts
  • #99309

    Participant
    Points: 21
    Rank: Member

    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?

    Regards
    Kamil

  • #99312

    Participant
    Points: 35
    Rank: Member

    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
    $SqlServer.Status
    
    • #99417

      Participant
      Points: 21
      Rank: Member

      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?

      Regards

The topic ‘Test if it is indeed a SQL Server behind a port’ is closed to new replies.