Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created June 25, 2018 16:35
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/b1f97fa34d9f4509e4554fea5021260a to your computer and use it in GitHub Desktop.
Save guitarrapc/b1f97fa34d9f4509e4554fea5021260a to your computer and use it in GitHub Desktop.
function Get-NetTCPConnectionCheck{
[CmdletBinding()]
param(
)
begin
{
$result = [ordered]@{}
}
process
{
$result.date = (Get-Date).ToString("yyyy/MM/dd HH:mm:dd:ss")
@("Listen","Established","TimeWait","CloseWait","LastAck","FinWait2") | %{$result.$_ = 0}
Get-NetTCPConnection | group state -NoElement | where name -in $result.Keys | %{$result.$($_.name) = $_.count}
}
end
{
return [PSCustomObject]$result
}
}
# 例のごとく $_ と Export を分岐
&{
while($true)
{
Get-NetTCPConnectionCheck | %{
$_ | Export-Csv -Path D:\hoge.csv -NoClobber -NoTypeInformation -Append -Encoding UTF8
$_}
sleep -Seconds 1
}
} | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment