Add local Windows Server inventory collection and validation; include core package
This commit is contained in:
16
powershell/Get-ServerNetwork.ps1
Normal file
16
powershell/Get-ServerNetwork.ps1
Normal file
@@ -0,0 +1,16 @@
|
||||
function Get-SamsaraNetwork {
|
||||
param($Result)
|
||||
$processes = @{}
|
||||
Invoke-SamsaraRead $Result 'Process names' {
|
||||
Get-Process -ErrorAction Stop | ForEach-Object { $processes[[int]$_.Id] = [string]$_.ProcessName }
|
||||
}
|
||||
Invoke-SamsaraRead $Result 'TCP connections' {
|
||||
$Result.data = @(Get-NetTCPConnection -ErrorAction Stop | ForEach-Object {
|
||||
$processName = if ($processes.ContainsKey([int]$_.OwningProcess)) { $processes[[int]$_.OwningProcess] } else { 'Unavailable or process exited' }
|
||||
[pscustomobject]@{ state = [string]$_.State; local_address = [string]$_.LocalAddress; local_port = [int]$_.LocalPort
|
||||
remote_address = [string]$_.RemoteAddress; remote_port = [int]$_.RemotePort
|
||||
pid = [int]$_.OwningProcess; process = $processName; direction = 'Unknown' }
|
||||
})
|
||||
}
|
||||
$Result.limitations += 'Point-in-time TCP only. Connection direction, historical activity, UDP and other network compartments are unverified. Process names may race process exit or be hidden.'
|
||||
}
|
||||
Reference in New Issue
Block a user