Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Get HostName for Each RemoteAddress IP in New Member

$
0
0

I have a PowerShell script, which has some variablie
1. $GetCon : Get Tcp Connection in Powershell
2. $hn : Get expand Remote-Address in $GetCon.
3. $rrt : is a Number of all results, it's all connection IP's.
4. $GNamess : is a variable to Create a new Member by name (urls) for $GetCon wich is a Get-NetTCPConnection. 
Finally I have a new member, it will be contain list of each Connections Host Names for Each IP Address in Get-TCPConnection RemoteAddress.
But we don't revive result of host's in the result, in the result I've one Host for each host's!
please get me an method to get all host's in the result.

Wrong Syntax:

$GetCon = Get-NetTCPConnection

$hn = $GetCon | select -expand RemoteAddress

$rrt = foreach ($IPs in $hn)
{

 [System.Net.Dns]::GetHostAddresses($IPs) | select-object IPAddressToString -expandproperty  IPAddressToString

}


$GNamess = foreach ($IPst in $GetCon) {

    $rrt = ([System.Net.Dns]::GetHostbyAddress($IPs) | select-object HostName -expandproperty  HostName)
    $IPst | Add-Member -NotePropertyName urls -NotePropertyValue $rrt -PassThru
}

$GetCon | select urls

Image Result: https://i.stack.imgur.com/Ov5Ye.png



Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>