Nslookup PS Script help

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 :slight_smile: 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"

Not really. If it works, it’s great, right? :slight_smile:

Actually there is a powershell version of netstat:

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