Thursday, January 5, 2012

Two methods to query psdrives

Both the methods below will query remote and local drives of all types:



Wednesday, January 4, 2012

Parse TCP and UDP ports from services file



# Parses TCP and UDP ports from services file on Windows 7

$a=gc C:\Windows\System32\drivers\etc\services
$tcp=$a | sls tcp
$udp=$a | sls udp

[array[]]$tcp=0..(($tcp.count) -1) | % { (($tcp.GetValue($_) -split("/"))[0])}
[array[]]$udp=0..(($udp.count) -1) | % { (($udp.GetValue($_) -split("/"))[0])}

[array[]]$tcp_service_ports=0..(($tcp.count) -1) | % { (($tcp.GetValue($_) -split(" "))[-1])}
[array[]]$udp_service_ports=0..(($udp.count) -1) | % { (($udp.GetValue($_) -split(" "))[-1])}

Count the number of binaries in your path

Powershell 3.0 CTP2

Count the number of binaries in your path:

([System.Environment]::GetEnvironmentVariables().Path -split(";") |% { ls $_ *.exe}).count