Created
June 25, 2018 16:35
-
-
Save guitarrapc/b1f97fa34d9f4509e4554fea5021260a 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 = [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