Wow, what a couple of weeks. Haven't posted much between the scripting games & Exchange 2010 training this week I've been really busy. Awaiting the official final results from the scripting games, but it looks like I've managed to snag 3rd in the 'Advanced Division'. Well...at least according to "Clint's Rules" which are different from the official rules - you can download the spreadsheet I created here. What can I say...I'm a little competitive by nature. But more importantly, man did I learn a lot from doing the exercises and from reading what other people submitted. This week I'll try to post one thing I learned each day (maybe even starting today if I can resist the play SC2 beta urge) this week since class is over at 4 and I'm all by myself. In fact....here we go, the thing I remember first is:
A way better method of looping/waiting for an event and then acting on it:
Look at lines 34-44 in Robert Robelo's Event 6 submission. Compare that to all the nasty global variables and junk I made to work inside the event handler in my submission for Event 6 (had to make a link to download, the link for my Event 6 submission blows up for some reason).
Which kinda ties into thing #1.5 that I learned - the scriptblocks you supply to the -Action parameter in Register-*Event create a separate variable scope that does not inherit the variables from the script scope etc. At least that's what it seems like....I could be wrong on that, I haven't looked for any documentation tbh.
So, in my opinion, the way that Robert does it is WAY better than the way I did it, which basically boils down to:
- Create ONE global variable that will hold the event object when it is raised
- In the -action parameter of Register-*Event just assign the $Event automatic variable (or a property of it if that's all you're interested in) to the global variable that you created in your script
- Sleep loop until that global variable isn't $null anymore.
Speaking of Robert, why aren't you reading his blog instead of mine? He rolled #1 in the Advanced division according to Clint's Rules....better go check out what he has to say.
Until tomorrow, bubye!! v(^_^)v