Nslookup PS Script help

This topic contains 2 replies, has 3 voices, and was last updated by  js 6 months, 3 weeks ago.

  • Author
  • #83314

    suresh krishnan

    Dear Community

    I have requirement to find out which database servers are my servers connected to . I do not have access to query SQL PS commands hence i come up with below script to query from server that i connected. The script is bit ok but i wanted to check with you all 🙂 to see if there is any other better way i can do this .

    $cmd = netstat -ano | findstr ":1433"
    $cmd = $cmd.split(10)
    $result = $cmd[10]
    $result = $result.replace(":1433", "")
    $DBServer = nslookup $result 
    $DBServer = $DBServer | select-string "Name"
    write-host "Server connected to $DBServer"
  • #83380

    Don Jones

    Not really. If it works, it's great, right? 🙂

  • #83413


    Actually there is a powershell version of netstat:

    Get-NetTCPConnection | where remoteport -eq 1433 | select -expand remoteaddress -first 1 | Resolve-DnsName

You must be logged in to reply to this topic.