I have this function:
Function BuildDaHash($data){
$arr=@{}
$j=0
$k=0
For ($i=0; $i -lt $data.count; $i++){
if ($data[$i] -match 'nmap scan report') {
$arr[$j]=@{}
$arr[$j][$k] = $data[$i]
$i++
$k++
Do {
$arr[$j][$k] = $data[$i].Split(' ')[0]
$i++
$k++
} While ($data[$i] -notmatch 'nmap scan report' -and $i -lt $data.count)
$j++
$k=0
$i--
}
}
return $arr
}
this function takes a long string (Nmap scan report) and build Hash table so i can then address it as follows: output of $arr[0][0] is 192.168.20.10 and then followed by ports like: $arr[0][1] = 22; $arr[0][2] = 80, etc.
If i call the function from the script like so
BuildDaHash($string)
i will get the output of the hash table, but if i want to get the output to a varbiable so i can work with it, it comes empty. meaning if i do this:
$test = BuildDaHash($string)
it comes empty, what am i missing here? i thought maybe it something with building an empty hash before like so:
$tst =@{}
$tst = BuildDaHash($string)
But that also comes empty
*EDIT I know Nmap has different formats available, im working with default txt, i have another function that reads the output and return a txt only with the ip and the open/filtered ports here is an example of $string:
Nmap scan report for 11.11.111.111
21/tcp filtered ftp
179/tcp filtered bgp
646/tcp filtered ldp
Nmap scan report for 22.22.222.12
21/tcp filtered ftp
111/tcp filtered rpcbind
179/tcp filtered bgp
646/tcp filtered ldp