Hashtable Import/Merge/Export Powershell
Posted on 2008-11-08
This is something I've attempted to do before, but did not succeed. Now I'm asking for something pretty interesting and I haven't seen much written about it on Google or EE.
Simply put, I want to make a hash table with values like "John Smith", "2" and "Jane Doe", "4". It starts by taking a survey of all the exchange mailboxes and whoever is over a certain amount of MBs, flags that user name and adds it to a temporary list. This can be an array since it's only a bunch of names. No numbers yet. Here's where it gets interesting. There will be a text file or csv, whichever is easier in a location accessible by the script. Let's call it "C:\HashTable.csv". It imports all the values from Hashtable.csv into a hashtable. Then it goes down the line and says "If a person exists in this hash table, increment their corresponding value by 1". Otherwise, just add them to the list, and give the key a value of 1. So the key is the persons name (because it's unique), and the value is how many days we've found them full on the server.
I tried to use a text file that outputs their names into it, and then counts it all up. That works but after a while the text file gets so sloppy, it's hard to read it. And it also pretty large after a few days.
Hopefully someone can cook something up. The hardest part I'm having is exporting the hashtable. Once I export it, I suppose it would be easy to import it. And even easier to do a "Does key exist" on the table, then if they do, increment their value by 1. Should be a cakewalk, right?
This has been something plaguing me for a few months and I shelved it because I got sidetracked with other projects. So whoever can fix this will get my 2000 points + my undying gratitude free of charge.