Get HostName for Each RemoteAddress IP in New Member
have powershell script, has variablie
1. $getcon
: tcp connection in powershell
2. $hn
: expand remote-address in $getcon.
3. $rrt
: number of results, it's connection ip's.
4. $gnamess
: variable create new member name (urls) for $getcon
wich get-nettcpconnection.
finally i have new member, contain list of each connections host names each ip address in get-tcpconnection remoteaddress.
but we don't revive result of host's in result, in result i've 1 host each host's!
please me method host's in 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
if find post has answered question, please mark answer. if find post helpful in anyway, please click vote helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
Windows Server > Windows PowerShell
Comments
Post a Comment