Here is an example for windows using FOR to parse netstat output then DO tasklist with /fi filter on pid to show process name. ... # pick last item: $pname = $(Get-Process -id $nar[-1]).ProcessName $ppath = $(Get-Process -id $nar[-1]).Path # print the ($n