Created
June 25, 2018 16:34
-
-
Save guitarrapc/eff6010849f3301c4cc93403c2dc21f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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