Added modules from WinAPI
This commit is contained in:
parent
56da334ea2
commit
b709d7e96b
24 changed files with 657 additions and 125 deletions
|
|
@ -1,30 +1,13 @@
|
|||
function Get-Netstat {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Remote and local view network tcp connections statistics and his used process
|
||||
Using Get-NetTCPConnection, ps, nslookup and Invoke-Command via WinRM
|
||||
.DESCRIPTION
|
||||
Example:
|
||||
Get-Netstat localhost # default
|
||||
Get-Netstat server-01 # remote host
|
||||
.LINK
|
||||
https://github.com/Lifailon
|
||||
#>
|
||||
Param (
|
||||
$srv="localhost"
|
||||
)
|
||||
if ($srv -like "localhost") {
|
||||
Get-NetTCPConnection -State Established,Listen | sort -Descending State | select CreationTime,LocalAddress,LocalPort,RemotePort,
|
||||
@{name="RemoteHostName";expression={((nslookup $_.RemoteAddress)[3]) -replace ".+:\s+"}},RemoteAddress,
|
||||
State,@{name="ProcessName";expression={(ps -Id $_.OwningProcess).ProcessName}},
|
||||
@{name="ProcessPath";expression={(ps -Id $_.OwningProcess).Path}} | Out-GridView -Title "Local netstat"
|
||||
}
|
||||
else {
|
||||
icm $srv {Get-NetTCPConnection -State Established,Listen | sort -Descending State | select CreationTime,LocalAddress,LocalPort,
|
||||
RemotePort,RemoteAddress,
|
||||
State,@{name="ProcessName";expression={(ps -Id $_.OwningProcess).ProcessName}},
|
||||
@{name="ProcessPath";expression={(ps -Id $_.OwningProcess).Path}}} | select CreationTime,LocalAddress,LocalPort,RemotePort,
|
||||
@{name="RemoteHostName";expression={((nslookup $_.RemoteAddress)[3]) -replace ".+:\s+"}},
|
||||
RemoteAddress,State,ProcessName,ProcessPath | Out-GridView -Title "Remote netstat to server: $srv"
|
||||
}
|
||||
function Get-NetStat {
|
||||
Get-NetTCPConnection -State Established,Listen | Sort-Object -Descending State |
|
||||
Select-Object @{name="ProcessName";expression={(Get-Process -Id $_.OwningProcess).ProcessName}},
|
||||
LocalAddress,
|
||||
LocalPort,
|
||||
RemotePort,
|
||||
@{name="RemoteHostName";expression={((nslookup $_.RemoteAddress)[3]) -replace ".+:\s+"}},
|
||||
RemoteAddress,
|
||||
State,
|
||||
CreationTime,
|
||||
@{Name="RunTime"; Expression={((Get-Date) - $_.CreationTime) -replace "\.\d+$"}},
|
||||
@{name="ProcessPath";expression={(Get-Process -Id $_.OwningProcess).Path}}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue