Skip to content

Instantly share code, notes, and snippets.

@jaredcnance
Created April 24, 2018 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredcnance/e1586af786eb480dd8ff18e86f1cdab8 to your computer and use it in GitHub Desktop.
Save jaredcnance/e1586af786eb480dd8ff18e86f1cdab8 to your computer and use it in GitHub Desktop.
$Total = Invoke-Command -ScriptBlock {netsh int ipv4 show dynamicport tcp}
$regex = new-object System.Text.RegularExpressions.Regex ('(Number of Ports : )(\d*)', [System.Text.RegularExpressions.RegexOptions]::MultiLine)
$Total = ($regex.Match($Total)).Groups[2].Value
$InUse = Invoke-Command -ScriptBlock {(netstat -an | ? {($_ -notmatch 'LISTENING')}).Count}
Write-Output “$InUse/$Total ports in use”
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment