title: Powershell Function return HashTable
body: <p>I have this function:</p>
  <pre><code>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
  }
  </code></pre>
  <p>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.</p>
  <p>If i call the function from the script like so</p>
  <pre><code>BuildDaHash($string)
  </code></pre>
  <p>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:</p>
  <pre><code>$test = BuildDaHash($string)
  </code></pre>
  <p>it comes empty, what am i missing here? i thought maybe it something with building an empty hash before like so:</p>
  <pre><code>$tst =@{}
  $tst = BuildDaHash($string)
  </code></pre>
  <p>But that also comes empty</p>
  <p>*<strong>EDIT</strong>
  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:</p>
  <pre><code>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
  </code></pre>