Count # of errors in error log & Compare | Powershell (V2) | Array Data Structures -


i have hashtable of error codes , max # of times acceptable them occur across directory of error logs. so:

key    value err1   2 err2   1 

this table created dynamically based on input control file (xml) # of elements can change.

i want able 'err1' , 'err2', count # of times occur, , compare hashtable.

so have this:

foreach($file in $logs){     foreach($key in $hashtable.keys){         if(select-string $file -pattern $key){             #get key value, increment counter key value (error code)         }     } }  #psuedo next step... <#  foreach($key in $hashtable.keys){       if (countfound > key.value) {      write-host $("error: " + $key + " occurred much."     }  } #> 

is there data structure in powershell @ storing variable/value pairs , modifiable?

i don't want create array each key value, add element array each time find matching error code in file, count different array's lengths. that's best solution can think of.

you can go oo way , have class represent each error type read external source , update error instances based on logic. since asked better structure hold data, focused on that. logic have.

$errorclass = @" public class error {     public error(string errorcode, int maxoccurances) {         errorcode = errorcode;         maxoccurances = maxoccurances;     }      public string errorcode;     public int maxoccurances;     public int actualoccurances; } "@  add-type -typedefinition $errorclass  $error1 = new-object error("err1", 2) # these values xml $error1.actualoccurances = 5 # update property based on logic  $error2 = new-object error("err2", 1) $error2.actualoccurances = 3  $errarray = @($error1, $error2)  foreach ($err in $errarray) {     if ($err.actualoccurances -gt $err.maxoccurances) {         write-host $("error: '" + $err.errorcode + "' occurred much.")     } } 

output:

error: 'err1' occurred much. error: 'err2' occurred much. 

Comments