Feeds:
Posts
Comments

Archive for the ‘powershell’ Category

$a='aa','aa1','aa2','bb','bb1','bb2'
$hashT=@{}

foreach ($i in $a)
{
 $re= $i -match '^(..)'
 $type=$matches[1]
 if (!$hashT.ContainsKey($type)){
      $hashT[$type]=@()  ##********   this is the key to treat the element as an array, otherwise it treats it like string
    }
  $hashT[$type]=$hashT[$type]+$i
 }

foreach ($i in $hashT['aa']){
   $i
 }

 foreach ($i in $hashT['bb']){
   $i
 }

Read Full Post »