Untitled

 avatar
unknown
plain_text
a year ago
829 B
14
Indexable
Import-Module ActiveDirectory
$servers = Get-ADComputer -Filter 'OperatingSystem -like "*Server*"' -Properties DNSHostName |
           Where-Object {$_.DNSHostName} | Select-Object -ExpandProperty DNSHostName

Invoke-Command -ComputerName $servers -ScriptBlock {
  param($ip)
  $conns = Get-NetTCPConnection -RemoteAddress $ip -State Established -ErrorAction SilentlyContinue
  foreach($c in $conns){
    $p = Get-Process -Id $c.OwningProcess -ErrorAction SilentlyContinue
    [pscustomobject]@{
      Server      = $env:COMPUTERNAME
      RemoteIP    = $ip
      RemotePort  = $c.RemotePort
      Process     = $p.ProcessName
      PID         = $c.OwningProcess
    }
  }
} -ArgumentList $ip -ErrorAction SilentlyContinue |
Export-Csv "$env:USERPROFILE\Desktop\Who_Uses_20-190-142-167.csv" -NoTypeInformation
Editor is loading...
Leave a Comment