Skip to content

Instantly share code, notes, and snippets.

@maravedi
Last active October 3, 2019 12:35
Show Gist options
  • Save maravedi/7db761c1d11ce01e8261ba6a0d263544 to your computer and use it in GitHub Desktop.
Save maravedi/7db761c1d11ce01e8261ba6a0d263544 to your computer and use it in GitHub Desktop.
PowerShell - Parse Greppable Nmap Output
$Data = [System.Collections.ArrayList]@(); ((cat .\Scan.txt | Select -Skip 1 | Select -SkipLast 1 | %{$Row = ""|Select Host,Status,Ports,OS; $Temp = $_ -Split '\t'; If(($Temp -Join ',') -notlike "*Status:*" -And ($Temp -Join ',') -like "*OS:*"){ $Row.Host = $Temp[0]; $Row.Status = ""; $Row.Ports = $Temp[1]; $Row.OS = $Temp[3]} ElseIf(($Temp -Join ',') -notlike "*Status:*"){$Row.Host = $Temp[0]; $Row.Status = ""; $Row.Ports = $Temp[1]; $Row.OS = $Temp[2]} Else {$Row.Host = $Temp[0]; $Row.Status = $Temp[1]; $Row.Ports = $Temp[2]; $Row.OS = ""}; [Void]$Data.Add($Row)}))
$Data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment