13 October 2008

List Net Apps

Lets say that you want a list of network apps running in windows at a given time. I have written a simple script in Powershell to handle this:
function global:get-netapps
{
$myfile = (& netstat -abno )
$mymatches = $myfile -match "\[(?.*\.exe)\]`$"
$results = ""
foreach ($line in $mymatches)
{
if ($results.Contains($line.Replace('[','').Replace(']','')) -eq 0)
{
$results += $line.Replace('[','').Replace(']','') + "`n"
}
}
$results

}
Set-Alias lsnetapps get-netapps -Scope "global"
just run: get-netapps or lsnetapps

Labels: , ,