This PowerShell script displays a list of processes on your local PC that have network connections, allows the user to select one of those processes, and then it outputs the network connections used by that process:
#This Script shows the Network Connections that have been established by any given process name:
#Display a list of Process Names that have network connections:
#Distinct List of “OwningProcess” values from the Get-NetTCPConnection command:
$owningprocess = (Get-NetTCPConnection | Select-Object -Unique OwningProcess).OwningProcess
#List of names of those processes:
$ProcessList = Get-Process | Where-Object {$_.Id -in $owningprocess} | Select-Object Name, Path
#User has to select a process from the GUI that displays the list before code will continue:
$ProcessName = $ProcessList | Out-GridView -Title “Select a Process” -PassThru
#Now, show the list of Network Connections used by this Process:
Get-Process -Name $ProcessName.Name | ForEach-Object { Get-NetTCPConnection -OwningProcess $_.Id -ErrorAction SilentlyContinue }