Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created June 25, 2018 16:34
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 guitarrapc/eff6010849f3301c4cc93403c2dc21f2 to your computer and use it in GitHub Desktop.
Save guitarrapc/eff6010849f3301c4cc93403c2dc21f2 to your computer and use it in GitHub Desktop.
function Get-NetTCPConnectionCheck{
[CmdletBinding()]
param(
)
begin
{
$result = @{}
}
process
{
$result.date = (Get-Date).ToString("yyyy/MM/dd HH:mm:dd:ss")
$connection = Get-NetTCPConnection
$statuslist = @("Listen","Established","TimeWait","CloseWait","LastAck")
$status = ($connection | group state -NoElement | where Name -in $statuslist).Name
foreach ($c in $($connection | group State -NoElement))
{
$status | %{
$s = $_
if (($c | where Name -eq $s).Name -ne $null)
{
$result.Add("$(($c | where Name -eq $s).Name)", ($c | where Name -eq $s).count)
}
}
}
}
end
{
return [PSCustomObject]$result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment