<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Wes' Puzzling Blog</title><link>https://weblogs.asp.net:443/whaggard/</link><description>... trying to solve the puzzles of .NET</description><item><title>MEF Preview 9 released</title><link>https://weblogs.asp.net:443/whaggard/mef-preview-9-released</link><description>&lt;P mce_keep="true"&gt;&lt;A href="http://mef.codeplex.com/" mce_href="http://mef.codeplex.com/"&gt;MEF&lt;/A&gt; preview 9 has been released on codeplex &lt;A href="http://mef.codeplex.com/releases/view/40606" mce_href="http://mef.codeplex.com/releases/view/40606"&gt;http://mef.codeplex.com/releases/view/40606&lt;/A&gt;. &lt;/P&gt;
&lt;P mce_keep="true"&gt;The only changes are some bug fixes for the .Net version and a couple additions to the SL version. &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;We brought back PackageCatalog but redesigned it&amp;nbsp;under&amp;nbsp;the name DeploymentCatalog and put it in System.ComponentModel.Composition.Initilization.dll&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;We renamed PartCreator to ExportFactory and put it in System.ComponentModel.Composition.Initilization.dll&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Renamed type PartInitializer to CompositionInitializer&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Renamed method CompositionHost.InitializeContainer to CompositionHost.Initialize&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;This drop contains a MEF.sln which loads in VS2008 and builds MEF against .Net 3.5 and MEFSL.sln which loads in VS2008 and builds MEF againts SL3. The API's are pretty much what we are shipping&amp;nbsp;in .Net 4.0 and SL4 SDK&amp;nbsp;respectively. However if you need a .Net 4 version of MEF we suggest that you install the RC version of .Net 4 and if you need an SL4 version of MEF you install the Silverlight 4 beta SDK.&lt;/P&gt;
&lt;P mce_keep="true"&gt;As aways if you have issues or questions related to MEF feel free to post them in our dicsussion forums at &lt;A href="http://mef.codeplex.com/Thread/List.aspx"&gt;http://mef.codeplex.com/Thread/List.aspx&lt;/A&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;For some more detailed explanations of the changes in this preview have a look at Mike Taulty's post &lt;A href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2010/02/17/new-mef-drop-preview-9-on-codeplex.aspx"&gt;http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2010/02/17/new-mef-drop-preview-9-on-codeplex.aspx&lt;/A&gt;.&lt;/P&gt;</description><pubDate>Wed, 24 Feb 2010 17:27:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/mef-preview-9-released</guid><category>.NET</category><category>MEF</category><category>News</category></item><item><title>MEF preview 5 released</title><link>https://weblogs.asp.net:443/whaggard/mef-preview-5-released</link><description>&lt;p&gt;My team released the 5th source code preview of &lt;a href="http://codeplex.com/mef"&gt;MEF&lt;/a&gt; (Managed Extensibility Framework). You can get the latest bits at &lt;a href="http://mef.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25797"&gt;MEF preview 5&lt;/a&gt;. A summary of the changes can be found on in the &lt;a href="http://mef.codeplex.com/Wiki/View.aspx?title=Release5"&gt;release notes&lt;/a&gt; but I will copy them here for convenience. If you have questions or concerns feel free to join the &lt;a href="http://mef.codeplex.com/Thread/List.aspx"&gt;discussion&lt;/a&gt;.&lt;/p&gt;  &lt;h4&gt;Namespace changes &lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;System.ComponentModel.Composition – For part authors. This namespace contains the import and export attributes as well as other APIs that part authors are likely to use. &lt;/li&gt;    &lt;li&gt;System.ComponentModel.Composition.Hosting – For hosters. This namespace contains the CompositionContainer, catalog implementations, and other APIs that hosters are likely to use. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Part discovery changes &lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;CompositionOptionsAttribute and DiscoveryMode have been removed. &lt;/li&gt;    &lt;li&gt;PartNotDiscoverableAttribute replaces [CompositionOptions(DiscoveryMode = DiscoveryMode.Never)] &lt;/li&gt;    &lt;li&gt;PartCreationPolicyAttribute can be used to specify part creation policy (Replaces CompositionOptionsAttribute.CreationPolicy) &lt;/li&gt;    &lt;li&gt;By default, exports on a base class will not be included in the exports for a derived class. &lt;/li&gt;    &lt;li&gt;The PartExportsInheritedAttribute can be applied to a base class to specify that exports on that class will be included in derived classes. &lt;b&gt;NOTE&lt;/b&gt;: If this attribute is used, and both the base and derived class have export attributes applied to them, there will be &lt;u&gt;multiple exports&lt;/u&gt; created for the same class. Also note that whatever metadata is applied to the export on the base class can’t be added to or overridden by the derived class &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Collection imports &lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;ImportManyAttribute should now be used on collection imports (in the future, an ImportAttribute will not be interpreted as a collection import even if it is applied to a collection type). &lt;/li&gt;    &lt;li&gt;Array imports are now supported. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Typed Imports/Exports &lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;Imports and Exports now match on type as well as contract. &lt;/li&gt;    &lt;li&gt;Exporters of string contracts such as [Export(“Foo”)] must now specify the type they expect to be imported as well. e.g. [Export(“Foo”, typeof(string))] &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Method exports &lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;Method exports can now be imported as custom delegates in addition to Action&amp;lt;…&amp;gt; and Func&amp;lt;…&amp;gt; delegates &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Directory Catalog &lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;The directory watching functionality has been removed. The Refresh() method has been added to explicitly update the catalog with new assemblies in the directory. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Removal of Caching / new infrastructure &lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;The old caching infrastructure has been removed. We’ve added a general purpose API that allows the implementation of catalog caching as well as supporting builders of custom programming models. The APIs are members of the static class System.ComponentModel.Composition.ReflectionModel.ReflectionModelServices. In the future we plan to ship a sample that shows how these APIs can be used to create cached catalogs. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;New sample application &lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;MEF Studio – a designer hosting sample. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Common compilation errors to expect when migrating previous code bases &lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;System.ComponentModel.Composition.Container does not exist -&amp;gt; Add reference to System.ComponentModel.Composition.Hosting namespace &lt;/li&gt;    &lt;li&gt;CompositionContainer does not contain method AddPart or Compose -&amp;gt; Need to start using CompositionBatch, or one of the helper extension methods ComposeParts or ComposeExportedObjects &lt;/li&gt;    &lt;li&gt;CompositionOptionsAttribute does not exist -&amp;gt; For CreationPolicy use PartCreationPolicyAttribute &lt;/li&gt;    &lt;li&gt;INotifyImportCompleted does not exist -&amp;gt; Use IPartImportsSatisfiedNotification interface and change method from ImportCompleted to OnImportsSatisfied &lt;/li&gt; &lt;/ul&gt;</description><pubDate>Wed, 08 Apr 2009 02:20:17 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/mef-preview-5-released</guid><category>.NET</category><category>MEF</category><category>News</category></item><item><title>Should MEF support non-shared components?</title><link>https://weblogs.asp.net:443/whaggard/should-mef-support-non-shared-components</link><description>&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Hamilton has &lt;A href="http://hammett.castleproject.org/?p=332" mce_href="http://hammett.castleproject.org/?p=332"&gt;posted&lt;/A&gt; about the question of whether or not MEF should support non-shared as well as shared components (non-shared==factory and shared==singleton in our current public bits). &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;In an ideal world we would love to support both but currently every solution we've come up with to support non-shared components has issues. We could pick a solution that we feel properly balances the advantages and disadvantages but that would require us to foresee exactly how the world is going to use MEF. While we believe we could pick a reasonable balance there is fear that we would pick the wrong balance for the majority of our future users. Therefore one approach to combat this is to not support non-shared components, at least in V1, and see what usage patterns reveal themselves in the wild and target that balance in V2.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt; 
&lt;P&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Do you feel that it would be a mistake for the MEF team to only support shared/singleton components in V1?&lt;/SPAN&gt;&lt;/I&gt;&lt;/B&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt; Keep in mind that there are patterns, as Hamilton &lt;A href="http://hammett.castleproject.org/?p=332"&gt;pointed out&lt;/A&gt;, to still support non-shared/factory if you needed that support in V1.&lt;/SPAN&gt;&lt;/P&gt;</description><pubDate>Mon, 10 Nov 2008 19:16:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/should-mef-support-non-shared-components</guid><category>.NET</category><category>MEF</category></item><item><title>MEF CTP2 released with source code.</title><link>https://weblogs.asp.net:443/whaggard/mef-ctp2-released-with-source-code</link><description>&lt;p&gt;My team &lt;a href="http://www.codeplex.com/MEF/Release/ProjectReleases.aspx?ReleaseId=17033"&gt;released&lt;/a&gt; MEF CTP2 on codeplex at &lt;a title="http://www.codeplex.com/MEF" href="http://www.codeplex.com/MEF"&gt;http://www.codeplex.com/MEF&lt;/a&gt;, this time with source code. We also created a number of documents (i.e. wiki pages) and samples that demonstrate how to use MEF. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;&lt;strong&gt;What problems does MEF solve? &lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;   &lt;em&gt;MEF presents a simple solution for the runtime extensibility problem. Until now, any application that wanted to support a &lt;/em&gt;&lt;a href="http://en.wikipedia.org/wiki/Plugin"&gt;&lt;em&gt;plugin model&lt;/em&gt;&lt;/a&gt;&lt;em&gt; needed to create its own infrastructure from scratch. Those plugins would often be application-specific and could not be reused across multiple implementations.&lt;/em&gt;     &lt;ul&gt;     &lt;li&gt;&lt;em&gt;MEF provides a standard way for the host application to expose itself and consume external extensions. Extensions, by their nature, can be reused amongst different applications. However, an extension could still be implemented in a way that is application-specific. Extensions themselves can depend on one another and MEF will make sure they are wired together in the correct order (another thing you won't have to worry about). &lt;/em&gt;&lt;/li&gt;      &lt;li&gt;&lt;em&gt;MEF offers a set of discovery approaches for your application to locate and load available extensions. &lt;/em&gt;&lt;/li&gt;      &lt;li&gt;&lt;em&gt;MEF allows tagging extensions with additional metadata which facilitates rich querying and filtering&lt;/em&gt; &lt;/li&gt;   &lt;/ul&gt;    &lt;p&gt;&lt;em&gt;[&lt;a href="http://www.codeplex.com/MEF/Wiki/View.aspx?title=Overview&amp;amp;referringTitle=Home"&gt;MEF Overview&lt;/a&gt;]&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;By all means please provide us with what you like and\or dislike about MEF at &lt;a href="http://www.codeplex.com/MEF/Thread/List.aspx"&gt;Discussions&lt;/a&gt;.&lt;/p&gt;</description><pubDate>Wed, 10 Sep 2008 05:28:21 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/mef-ctp2-released-with-source-code</guid><category>MEF</category><category>News</category></item><item><title>First Managed Extensibility Framework (MEF) bits released</title><link>https://weblogs.asp.net:443/whaggard/first-managed-extensibility-framework-mef-bits-released</link><description>&lt;p&gt;Today was a big day for my team because we released the bits for the first CTP of the &lt;a href="http://code.msdn.microsoft.com/mef"&gt;Managed Extensibility Framework (MEF).&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://code.msdn.microsoft.com/mef"&gt;MEF&lt;/a&gt; is a framework that allows developers to declare what they need (i.e. Imports) and what they provide (i.e. Exports) and then automatically wire up everything at run-time. While that may be a slight over simplification it is the basic idea and can lead to a very loosely coupled system which can easily be extended and evolve overtime.&lt;/p&gt;  &lt;p&gt;The primary goal of this CTP is to get the bits into people’s hands early to gather feedback from the community and feed it back into the product. We have already gotten some good feedback in response to &lt;a href="http://blogs.msdn.com/kcwalina/default.aspx"&gt;Krzysztof&lt;/a&gt;’s blog &lt;a href="http://blogs.msdn.com/kcwalina/archive/2008/04/25/MEF.aspx"&gt;post about MEF&lt;/a&gt;, and some of that feedback has already made its way into the CTP. Rest assured that there are still community asks that we are still actively working hard on.&lt;/p&gt;  &lt;p&gt;Keep in mind these bits are very early and you should not get hung up on the names and exact shape of the API’s because they are likely to change. What we would really like is feedback on the basic concepts and any scenarios you feel MEF would be useful for but needs some fine tuning.&lt;/p&gt;  &lt;p&gt;To get your hands dirty &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mef&amp;amp;DownloadId=2217"&gt;download&lt;/a&gt; the bits and have a look at the sample applications and docs. If you have questions or feedback by all means don’t hesitate to stop by our &lt;a href="http://forums.msdn.microsoft.com/en-US/MEFramework/threads/"&gt;forum&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Expect so see some more posts from me and some of my teammates (&lt;a href="http://blogs.msdn.com/mirceat/default.aspx"&gt;Mitch&lt;/a&gt;, &lt;a href="http://davesbox.com/"&gt;David&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/kcwalina/default.aspx"&gt;Krzysztof&lt;/a&gt;) on &lt;a href="http://code.msdn.microsoft.com/mef"&gt;MEF&lt;/a&gt; in the coming months. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description><pubDate>Thu, 05 Jun 2008 05:07:39 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/first-managed-extensibility-framework-mef-bits-released</guid><category>.NET</category><category>MEF</category><category>News</category></item><item><title>Opening files from the VS "Quick find combo"</title><link>https://weblogs.asp.net:443/whaggard/opening-files-from-the-vs-quot-quick-find-combo-quot</link><description>&lt;p&gt;&lt;strong&gt;Ctrl+/ &lt;/strong&gt;is quickly becoming one of my favorite and most used hotkey in Visual Studio. Pressing it will jump you to the "Quick find Combo" with a "&amp;gt;" already type in for you (which means interpret the text as a VS command). &lt;/p&gt; &lt;p&gt;If you are like me you hate hunting through the Solution Explorer looking for files, especially on large solutions, you might be interested in the &lt;strong&gt;Ctrl+/&lt;/strong&gt; | "&amp;gt;of " command.&amp;nbsp; &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;As &lt;/em&gt;&lt;a href="http://www.alteridem.net/"&gt;&lt;em&gt;Robert Prouse&lt;/em&gt;&lt;/a&gt;&lt;em&gt; explains:&lt;br&gt;&lt;/em&gt;&lt;em&gt;&lt;br&gt;Here is a cool Visual Studio feature that almost nobody knows about. If you want to open up a file in your solution, but can’t be bothered to dig down through your projects and folders to find it, try this,&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;ol&gt; &lt;li&gt;&lt;em&gt;Click in the Find box in the toolbar, &lt;/em&gt; &lt;li&gt;&lt;em&gt;Type &amp;gt;of followed by a space, then begin the name of the file you are looking for. &lt;/em&gt; &lt;li&gt;&lt;em&gt;An auto-complete drop down will appear as you type filtering all the files in all your projects in your solution. Continue typing until the list is short enough to fine the one you want. Select it and hit enter. &lt;/em&gt; &lt;li&gt;&lt;em&gt;The file will open in the editor. &lt;/em&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;em&gt;&lt;img height="218" alt="openfile" src="http://www.alteridem.net/wp-content/uploads/2007/09/openfile.png" width="265" border="0"&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;[&lt;/em&gt;&lt;a href="http://www.alteridem.net/2007/09/11/quickly-findopen-a-file-in-visual-studio/"&gt;&lt;em&gt;Quickly Find/Open a File in Visual Studio&lt;/em&gt;&lt;/a&gt;&lt;em&gt;]&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;The best part of this auto complete drop down is that it actually gives you a flat list view of all the files in the solution which is just plain cool :)&lt;/p&gt; &lt;p&gt;As if that wasn't enough &lt;a href="http://www.aaronlerch.com/blog/"&gt;Aaron Lerch&lt;/a&gt; posted &lt;a href="http://www.aaronlerch.com/blog/2007/09/11/the-talented-mr-editgotofindcombo/"&gt;The Talented Mr. Edit.GoToFindCombo&lt;/a&gt; which lists some other cool features of the "Quick find combo".&lt;/p&gt;</description><pubDate>Thu, 27 Mar 2008 04:25:30 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/opening-files-from-the-vs-quot-quick-find-combo-quot</guid><category>.NET</category><category>Tips and Tricks</category></item><item><title>Job openings on the .NET Framework Core Team</title><link>https://weblogs.asp.net:443/whaggard/job-openings-on-the-net-framework-core-team</link><description>&lt;blockquote&gt; &lt;p&gt;&lt;em&gt;We have been incubating ideas about building a simple extensibility framework for some time. Now, as plans for the next version of the .NET Framework crystallize a bit more, we decided to productize the project. As a result, we have opened a job position (and most probably will be opening more) on the .NET Framework team. If you are interested, please see details &lt;/em&gt;&lt;a href="http://members.microsoft.com/careers/search/details.aspx?JobID=508DA780-65F1-480C-B831-F72A0FAA91E9&amp;amp;start=1&amp;amp;interval=10&amp;amp;SortCol=DatePosted"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;&lt;em&gt; and send me an email at “kcwalina at microsoft.com.”&lt;/em&gt;  &lt;p&gt;&lt;em&gt;So, what is this extensibility framework? Initially, it will be a low level core .NET Framework feature to make it easy for applications to expose extensibility points and consume extensions. Think about what for example FxCop has to do define rule contracts and load rule implemented by the community&lt;b&gt;. &lt;/b&gt;These are the basics, and we can talk about the broader and longer term vision when you come to Redmond for an interview :-)&lt;b&gt;&lt;/b&gt;&lt;/em&gt;  &lt;p&gt;&lt;em&gt;This is a technical Program Manager position&lt;b&gt; &lt;/b&gt;in Redmond, WA, and it’s basically exactly the job I did when I joined Microsoft. Besides working on the Framework features, all Program Managers on the core team have opportunities to work on API design and architecture projects.&lt;/em&gt;  &lt;p&gt;&lt;em&gt;[&lt;a href="http://blogs.msdn.com/kcwalina/archive/2008/03/14/8209671.aspx"&gt;Job Openings on the .NET Framework Core Team&lt;/a&gt;]&lt;/em&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;I'm a developer on &lt;a href="http://blogs.msdn.com/kcwalina/default.aspx"&gt;Kyzysztof&lt;/a&gt;'s team and we are looking for a few good people for &lt;a href="http://members.microsoft.com/careers/search/details.aspx?JobID=508DA780-65F1-480C-B831-F72A0FAA91E9&amp;amp;start=1&amp;amp;interval=10&amp;amp;SortCol=DatePosted"&gt;PM&lt;/a&gt; and &lt;a href="http://members.microsoft.com/careers/search/details.aspx?JobID=E4A1FBC3-E3ED-4B28-A667-6DE45D9816E7&amp;amp;AllCl=Y&amp;amp;start=1&amp;amp;interval=11&amp;amp;SortCol=DatePosted&amp;amp;SortOrder=DEF"&gt;D&lt;/a&gt;&lt;a href="http://members.microsoft.com/careers/search/details.aspx?JobID=4FD4315E-FE8F-4DE8-B5BF-65C5A3C5E90D&amp;amp;AllCl=Y&amp;amp;start=1&amp;amp;interval=11&amp;amp;SortCol=DatePosted&amp;amp;SortOrder=DEF"&gt;e&lt;/a&gt;&lt;a href="http://members.microsoft.com/careers/search/details.aspx?JobID=D6DAF3BF-C0F6-4030-B298-350892B66F99&amp;amp;start=1&amp;amp;interval=10&amp;amp;SortCol=DatePosted"&gt;v&lt;/a&gt; positions so by all means if you are interested in extensibility and API design please apply.&lt;/p&gt;</description><pubDate>Sun, 16 Mar 2008 21:19:38 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/job-openings-on-the-net-framework-core-team</guid><category>.NET</category><category>News</category></item><item><title>2008 Scripting Games - My solutions</title><link>https://weblogs.asp.net:443/whaggard/2008-scripting-games-my-solutions</link><description>&lt;p&gt;&lt;/p&gt; &lt;p&gt;Here are my solutions to the &lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/default.mspx"&gt;2008 Scripting Games&lt;/a&gt; scripting competition. This is a rather large post but I decided one post would be better than posting them all individually, this way they will all be in one place when I want to find them later. I had fun and I learned a lot of new cool things about Powershell while working through the problems. If you are trying to learn Powershell I would definitely recommend working through them to force yourself to learn the details. &lt;/p&gt; &lt;p&gt;Disclaimer: These script samples are by no means perfect but they are the unedited solutions that I submitted so they do solve the problems. They are provided as-is and you should use them at your own risk.&lt;/p&gt; &lt;h2&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/beginner.mspx"&gt;Powershell beginner division&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent1.mspx"&gt;Event 1: Pairing Off&lt;/a&gt; &lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/bpssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: green"&gt;# first char in card is A, 1, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K &lt;br&gt;# second char in card is H - Hearts, S - Spades, C - Clubs, D - Diamonds&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$cards&lt;/span&gt; = @(&lt;span style="color: maroon"&gt;"7S"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"5H"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"7D"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"7C"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"KC"&lt;/span&gt;); &lt;span style="color: #35687d"&gt;$numPairs&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;;

&lt;span style="color: blue"&gt;for&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$cards&lt;/span&gt;.Length; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;++) &lt;br&gt;{
  &lt;span style="color: blue"&gt;for&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$j&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$i&lt;/span&gt; + &lt;span style="color: maroon"&gt;1&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$j&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$cards&lt;/span&gt;.Length; &lt;span style="color: #35687d"&gt;$j&lt;/span&gt;++)
  {
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$cards&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;][&lt;span style="color: maroon"&gt;0&lt;/span&gt;] -eq &lt;span style="color: #35687d"&gt;$cards&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$j&lt;/span&gt;][&lt;span style="color: maroon"&gt;0&lt;/span&gt;])
    {
      &lt;span style="color: #35687d"&gt;$numPairs&lt;/span&gt;++;
    }
  }
}

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: #35687d"&gt;$numPairs&lt;/span&gt;;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent2.mspx"&gt;Event 2: True Type&lt;/a&gt; &lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/bpssol02.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$fonts&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;Get-Item&lt;/span&gt; &lt;span style="color: maroon"&gt;"HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts"&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$truetypes&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$fonts&lt;/span&gt;.Property | &lt;span style="color: blue"&gt;where&lt;/span&gt; { &lt;span style="color: #35687d"&gt;$_&lt;/span&gt; -match &lt;span style="color: maroon"&gt;"\(TrueType\)"&lt;/span&gt; }

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"TrueType Fonts:"&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$truetypes&lt;/span&gt;

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"TrueType: $($trueTypes.Count)"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Total: $($fonts.ValueCount)"&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent3.mspx"&gt;Event 3: Let’s Get Together&lt;/a&gt; &lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/bpssol03.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$firstLines&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;dir&lt;/span&gt; &lt;span style="color: maroon"&gt;"C:\Scripts\*.txt"&lt;/span&gt; | % { &lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; &lt;span style="color: #35687d"&gt;$_&lt;/span&gt; -totalCount &lt;span style="color: maroon"&gt;1&lt;/span&gt; }
&lt;span style="color: #35687d"&gt;$firstlines&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;Out-File&lt;/span&gt; -encoding ASCII &lt;span style="color: maroon"&gt;"c:\scripts\newfile.txt"&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent4.mspx"&gt;Event 4: Count Yourself In&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/bpssol04.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$c&lt;/span&gt;=&lt;span style="color: maroon"&gt;0&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; &lt;span style="color: #35687d"&gt;$MyInvocation&lt;/span&gt;.MyCommand.Definition | % { &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Length }
&lt;span style="color: #35687d"&gt;$c&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent5.mspx"&gt;Event 5: What’s the Difference&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/bpssol05.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;param([DateTime] &lt;span style="color: #35687d"&gt;$d&lt;/span&gt;)

&lt;span style="color: #35687d"&gt;$t&lt;/span&gt; = [DateTime]::Today

&lt;span style="color: #35687d"&gt;$ts&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$d&lt;/span&gt; - &lt;span style="color: #35687d"&gt;$t&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$ms&lt;/span&gt; = (&lt;span style="color: #35687d"&gt;$d&lt;/span&gt;.Month - &lt;span style="color: #35687d"&gt;$t&lt;/span&gt;.Month) + &lt;span style="color: maroon"&gt;12&lt;/span&gt; * (&lt;span style="color: #35687d"&gt;$d&lt;/span&gt;.Year - &lt;span style="color: #35687d"&gt;$t&lt;/span&gt;.Year);

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; (&lt;span style="color: maroon"&gt;"Days: "&lt;/span&gt; + &lt;span style="color: #35687d"&gt;$ts&lt;/span&gt;.Days)
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; (&lt;span style="color: maroon"&gt;"Months: "&lt;/span&gt; + &lt;span style="color: #35687d"&gt;$ms&lt;/span&gt;)

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$d&lt;/span&gt;.Day -lt &lt;span style="color: #35687d"&gt;$t&lt;/span&gt;.Day) { &lt;span style="color: #35687d"&gt;$ms&lt;/span&gt;--; }    
                
&lt;span style="color: #35687d"&gt;$ts&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$d&lt;/span&gt; - &lt;span style="color: #35687d"&gt;$t&lt;/span&gt;.AddMonths(&lt;span style="color: #35687d"&gt;$ms&lt;/span&gt;)

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; (&lt;span style="color: maroon"&gt;"Months/Days: "&lt;/span&gt; + &lt;span style="color: #35687d"&gt;$ms&lt;/span&gt; + &lt;span style="color: maroon"&gt;" / "&lt;/span&gt; + &lt;span style="color: #35687d"&gt;$ts&lt;/span&gt;.Days)&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent6.mspx"&gt;Event 6: Coffee Break&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/bpssol06.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$cfile&lt;/span&gt; = (&lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; &lt;span style="color: maroon"&gt;"C:\Scripts\coffee.txt"&lt;/span&gt;)

&lt;span style="color: #35687d"&gt;$orders&lt;/span&gt; = @{}
&lt;span style="color: blue"&gt;foreach&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$o&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: #35687d"&gt;$cfile&lt;/span&gt;)
{
    &lt;span style="color: #35687d"&gt;$d&lt;/span&gt;, &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$o&lt;/span&gt;.Split(&lt;span style="color: maroon"&gt;" "&lt;/span&gt;)
    &lt;span style="color: #35687d"&gt;$orders&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$d&lt;/span&gt;] += [int]&lt;span style="color: #35687d"&gt;$c&lt;/span&gt;;
}
&lt;span style="color: #35687d"&gt;$orders&lt;/span&gt;.Remove(&lt;span style="color: maroon"&gt;"Office"&lt;/span&gt;);

&lt;span style="color: #35687d"&gt;$orders&lt;/span&gt;.GetEnumerator() | % { &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Name + &lt;span style="color: maroon"&gt;" "&lt;/span&gt; + &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Value) }&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent7.mspx"&gt;Event 7: Squashing Bugs&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/bpssol07.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Get-ChildItem&lt;/span&gt; C:\Scripts -recurse)
{
    &lt;span style="color: blue"&gt;if&lt;/span&gt; ((&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;.CreationTime -lt ($(&lt;span style="color: #2b91af"&gt;Get-Date&lt;/span&gt;).AddDays(-&lt;span style="color: maroon"&gt;10&lt;/span&gt;))) -and (&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;.Extension -eq &lt;span style="color: maroon"&gt;".txt"&lt;/span&gt;))
    {
         &lt;span style="color: #2b91af"&gt;Copy-Item&lt;/span&gt; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;.FullName C:\old
         &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;.Name
         &lt;span style="color: #35687d"&gt;$x&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$x&lt;/span&gt; + &lt;span style="color: maroon"&gt;1&lt;/span&gt;
    }
}

&lt;span style="color: maroon"&gt;""&lt;/span&gt;
&lt;span style="color: maroon"&gt;"Total Files: "&lt;/span&gt; + &lt;span style="color: #35687d"&gt;$x&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent8.mspx"&gt;Event 8: Random Guess&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/bpssol08.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$r&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;New-Object&lt;/span&gt; System.Random
&lt;span style="color: #35687d"&gt;$low&lt;/span&gt; = &lt;span style="color: maroon"&gt;1&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$high&lt;/span&gt; = &lt;span style="color: maroon"&gt;50&lt;/span&gt;
[int]&lt;span style="color: #35687d"&gt;$num&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$r&lt;/span&gt;.Next(&lt;span style="color: #35687d"&gt;$low&lt;/span&gt;, &lt;span style="color: #35687d"&gt;$high&lt;/span&gt;)
&lt;span style="color: #35687d"&gt;$guess&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$guesses&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;

&lt;span style="color: blue"&gt;while&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$num&lt;/span&gt; -ne &lt;span style="color: #35687d"&gt;$guess&lt;/span&gt;)
{
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -NoNewline &lt;span style="color: maroon"&gt;"Guess a number between $low and $high : "&lt;/span&gt;
    [int]&lt;span style="color: #35687d"&gt;$guess&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;Read-Host&lt;/span&gt;
    
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$guess&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$num&lt;/span&gt;)
    {
        &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Too Low!"&lt;/span&gt;
        &lt;span style="color: #35687d"&gt;$low&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$guess&lt;/span&gt;
    }
    &lt;span style="color: blue"&gt;else&lt;/span&gt;
    {
        &lt;span style="color: blue"&gt;if&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$guess&lt;/span&gt; -gt &lt;span style="color: #35687d"&gt;$num&lt;/span&gt;)
        {
            &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Too High!"&lt;/span&gt;
            &lt;span style="color: #35687d"&gt;$high&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$guess&lt;/span&gt;
        }
    }
    &lt;span style="color: #35687d"&gt;$guesses&lt;/span&gt;++
}

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Random number was $num"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Total guesses: $guesses"&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent9.mspx"&gt;Event 9: Pool Party&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/bpssol09.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$adOpenStatic&lt;/span&gt; = &lt;span style="color: maroon"&gt;3&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$adLockOptimistic&lt;/span&gt; = &lt;span style="color: maroon"&gt;3&lt;/span&gt;

&lt;span style="color: #35687d"&gt;$objConnection&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;New-Object&lt;/span&gt; -comobject ADODB.Connection
&lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;New-Object&lt;/span&gt; -comobject ADODB.Recordset

&lt;span style="color: #35687d"&gt;$objConnection&lt;/span&gt;.Open(&lt;span style="color: maroon"&gt;"Provider=Microsoft.Jet.OLEDB.4.0; Data Source= c:\scripts\pool.mdb"&lt;/span&gt;)
&lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.Open(&lt;span style="color: maroon"&gt;"Select * from SwimmingPool"&lt;/span&gt;, &lt;span style="color: #35687d"&gt;$objConnection&lt;/span&gt;,&lt;span style="color: #35687d"&gt;$adOpenStatic&lt;/span&gt;,&lt;span style="color: #35687d"&gt;$adLockOptimistic&lt;/span&gt;)

&lt;span style="color: blue"&gt;do&lt;/span&gt; 
{
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; (&lt;span style="color: maroon"&gt;"  Name: "&lt;/span&gt; + &lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.Fields.Item(&lt;span style="color: maroon"&gt;"Customer"&lt;/span&gt;).Value)
    [int]&lt;span style="color: #35687d"&gt;$length&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.Fields.Item(&lt;span style="color: maroon"&gt;"Length"&lt;/span&gt;).Value;
    [int]&lt;span style="color: #35687d"&gt;$width&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.Fields.Item(&lt;span style="color: maroon"&gt;"Width"&lt;/span&gt;).Value;
    [int]&lt;span style="color: #35687d"&gt;$depth&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.Fields.Item(&lt;span style="color: maroon"&gt;"Depth"&lt;/span&gt;).Value;
    [bool]&lt;span style="color: #35687d"&gt;$slope&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.Fields.Item(&lt;span style="color: maroon"&gt;"Slope"&lt;/span&gt;).Value;
    [int]&lt;span style="color: #35687d"&gt;$sstart&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.Fields.Item(&lt;span style="color: maroon"&gt;"SStart"&lt;/span&gt;).Value;
    [int]&lt;span style="color: #35687d"&gt;$send&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.Fields.Item(&lt;span style="color: maroon"&gt;"SEnd"&lt;/span&gt;).Value;
    
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$slope&lt;/span&gt;)
    {
        &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; (&lt;span style="color: maroon"&gt;"    Volume of Water: "&lt;/span&gt; + (&lt;span style="color: #35687d"&gt;$length&lt;/span&gt; * &lt;span style="color: #35687d"&gt;$width&lt;/span&gt; * ((&lt;span style="color: #35687d"&gt;$send&lt;/span&gt; + &lt;span style="color: #35687d"&gt;$sstart&lt;/span&gt;)/&lt;span style="color: maroon"&gt;2&lt;/span&gt;) * &lt;span style="color: maroon"&gt;1000&lt;/span&gt;))
    }
    &lt;span style="color: blue"&gt;else&lt;/span&gt;
    {
        &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; (&lt;span style="color: maroon"&gt;"    Volume of Water: "&lt;/span&gt; + (&lt;span style="color: #35687d"&gt;$length&lt;/span&gt; * &lt;span style="color: #35687d"&gt;$width&lt;/span&gt; * &lt;span style="color: #35687d"&gt;$depth&lt;/span&gt; * &lt;span style="color: maroon"&gt;1000&lt;/span&gt;))
    }
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt;
    &lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.MoveNext()
} &lt;span style="color: blue"&gt;until&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.EOF -eq &lt;span style="color: #35687d"&gt;$True&lt;/span&gt;)


&lt;span style="color: #35687d"&gt;$objRecordset&lt;/span&gt;.Close()
&lt;span style="color: #35687d"&gt;$objConnection&lt;/span&gt;.Close()&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent10.mspx"&gt;Event 10: Bowling&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/bpssol10.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$arrFrames&lt;/span&gt; = &lt;span style="color: maroon"&gt;2&lt;/span&gt;,&lt;span style="color: maroon"&gt;5&lt;/span&gt;,&lt;span style="color: maroon"&gt;7&lt;/span&gt;,&lt;span style="color: maroon"&gt;"/"&lt;/span&gt;,&lt;span style="color: maroon"&gt;8&lt;/span&gt;,&lt;span style="color: maroon"&gt;1&lt;/span&gt;,&lt;span style="color: maroon"&gt;"X"&lt;/span&gt;,&lt;span style="color: maroon"&gt;9&lt;/span&gt;,&lt;span style="color: maroon"&gt;"/"&lt;/span&gt;,&lt;span style="color: maroon"&gt;5&lt;/span&gt;,&lt;span style="color: maroon"&gt;3&lt;/span&gt;,&lt;span style="color: maroon"&gt;7&lt;/span&gt;,&lt;span style="color: maroon"&gt;0&lt;/span&gt;,&lt;span style="color: maroon"&gt;4&lt;/span&gt;,&lt;span style="color: maroon"&gt;5&lt;/span&gt;,&lt;span style="color: maroon"&gt;"X"&lt;/span&gt;,&lt;span style="color: maroon"&gt;2&lt;/span&gt;,&lt;span style="color: maroon"&gt;0&lt;/span&gt;

&lt;span style="color: #35687d"&gt;$frames&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$arrFrames&lt;/span&gt; -replace &lt;span style="color: maroon"&gt;"X"&lt;/span&gt;,&lt;span style="color: maroon"&gt;"10"&lt;/span&gt;
&lt;span style="color: blue"&gt;for&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;.Count; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;++) { &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;] -eq &lt;span style="color: maroon"&gt;"/"&lt;/span&gt;) { &lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;] = &lt;span style="color: maroon"&gt;10&lt;/span&gt; - [int]&lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;-&lt;span style="color: maroon"&gt;1&lt;/span&gt;]; } }
[int[]]&lt;span style="color: #35687d"&gt;$frames&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;;

&lt;span style="color: #35687d"&gt;$score&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;;
&lt;span style="color: #35687d"&gt;$fc&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;;
&lt;span style="color: blue"&gt;for&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$arrFrames&lt;/span&gt;.Count -and &lt;span style="color: #35687d"&gt;$fc&lt;/span&gt; -lt &lt;span style="color: maroon"&gt;10&lt;/span&gt;;)
{
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;] -eq &lt;span style="color: maroon"&gt;10&lt;/span&gt;)
    {
        &lt;span style="color: #35687d"&gt;$score&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;] + &lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;+&lt;span style="color: maroon"&gt;1&lt;/span&gt;] + &lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;+&lt;span style="color: maroon"&gt;2&lt;/span&gt;];
        &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;++; &lt;span style="color: #35687d"&gt;$fc&lt;/span&gt;++;
    }
    &lt;span style="color: blue"&gt;else&lt;/span&gt;
    {
        &lt;span style="color: #35687d"&gt;$fs&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;] + &lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;+&lt;span style="color: maroon"&gt;1&lt;/span&gt;];
        
        &lt;span style="color: #35687d"&gt;$score&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$fs&lt;/span&gt;;
        &lt;span style="color: #35687d"&gt;$i&lt;/span&gt; += &lt;span style="color: maroon"&gt;2&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$fc&lt;/span&gt;++;
        
        &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$fs&lt;/span&gt; -eq &lt;span style="color: maroon"&gt;10&lt;/span&gt;) { &lt;span style="color: #35687d"&gt;$score&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$frames&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;]; }
    }
}
&lt;span style="color: #35687d"&gt;$score&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/advanced.mspx"&gt;Powershell advanced division&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent1.mspx"&gt;Event 1: Could I Get Your Phone Number?&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt; ConvertLetterToNumber([char] &lt;span style="color: #35687d"&gt;$letter&lt;/span&gt;) &lt;br&gt;{
    &lt;span style="color: blue"&gt;switch&lt;/span&gt; -regex (&lt;span style="color: #35687d"&gt;$letter&lt;/span&gt;)
    {
        &lt;span style="color: maroon"&gt;"[abc]"&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: maroon"&gt;"2"&lt;/span&gt;; }
        &lt;span style="color: maroon"&gt;"[def]"&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: maroon"&gt;"3"&lt;/span&gt;; }
        &lt;span style="color: maroon"&gt;"[ghi]"&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: maroon"&gt;"4"&lt;/span&gt;; }
        &lt;span style="color: maroon"&gt;"[jkl]"&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: maroon"&gt;"5"&lt;/span&gt;; }
        &lt;span style="color: maroon"&gt;"[mno]"&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: maroon"&gt;"6"&lt;/span&gt;; }
        &lt;span style="color: maroon"&gt;"[prs]"&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: maroon"&gt;"7"&lt;/span&gt;; }
        &lt;span style="color: maroon"&gt;"[tuv]"&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: maroon"&gt;"8"&lt;/span&gt;; }
        &lt;span style="color: maroon"&gt;"[wxy]"&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: maroon"&gt;"9"&lt;/span&gt;; }
        default { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: maroon"&gt;""&lt;/span&gt;; }
    }
}

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -nonewline &lt;span style="color: maroon"&gt;"Enter phone number (XXXXXXX): "&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$number&lt;/span&gt; = (&lt;span style="color: #2b91af"&gt;Read-Host&lt;/span&gt;);

&lt;span style="color: blue"&gt;if&lt;/span&gt; (!(&lt;span style="color: #35687d"&gt;$number&lt;/span&gt; -match &lt;span style="color: maroon"&gt;"^\d{7}$"&lt;/span&gt;))
{
    &lt;span style="color: #2b91af"&gt;Write-Error&lt;/span&gt; &lt;span style="color: maroon"&gt;"Please enter a number in format XXXXXXX"&lt;/span&gt;;
    exit;
}

&lt;span style="color: #35687d"&gt;$foundWord&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$null&lt;/span&gt;;

&lt;span style="color: #35687d"&gt;$file&lt;/span&gt; = [System.IO.File]::OpenText(&lt;span style="color: maroon"&gt;"c:\scripts\wordlist.txt"&lt;/span&gt;);

&lt;span style="color: blue"&gt;while&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$word&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$file&lt;/span&gt;.ReadLine())
{
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$word&lt;/span&gt;.Length -eq &lt;span style="color: maroon"&gt;7&lt;/span&gt;)
    {
        &lt;span style="color: #35687d"&gt;$i&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;;
        &lt;span style="color: blue"&gt;while&lt;/span&gt; ((ConvertLetterToNumber &lt;span style="color: #35687d"&gt;$word&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;]) -eq &lt;span style="color: #35687d"&gt;$number&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;]) { &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;++; }
        
        &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; -eq &lt;span style="color: maroon"&gt;7&lt;/span&gt;)
        {
            &lt;span style="color: #35687d"&gt;$foundWord&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$word&lt;/span&gt;;
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        }
    }
}

&lt;span style="color: #35687d"&gt;$file&lt;/span&gt;.Close();

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$foundWord&lt;/span&gt; -eq &lt;span style="color: #35687d"&gt;$null&lt;/span&gt;)
{
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Sorry no such word 7 letter word in the list!"&lt;/span&gt;; 
} 
&lt;span style="color: blue"&gt;else&lt;/span&gt; 
{
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Found 7 letter word: $foundWord"&lt;/span&gt;; 
}&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent2.mspx"&gt;Event 2: Skating on Thin Ice&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$skaterScores&lt;/span&gt; = @();
&lt;span style="color: blue"&gt;foreach&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$skaterLine&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; &lt;span style="color: maroon"&gt;"c:\scripts\skaters.txt"&lt;/span&gt;)) &lt;br&gt;{
    &lt;span style="color: #35687d"&gt;$name&lt;/span&gt;, &lt;span style="color: #35687d"&gt;$scores&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$skaterLine&lt;/span&gt; -split &lt;span style="color: maroon"&gt;","&lt;/span&gt;
    
    &lt;span style="color: green"&gt;# Sort for easy removal of best and worst score&lt;/span&gt;
    &lt;span style="color: #35687d"&gt;$scores&lt;/span&gt; = [int[]]&lt;span style="color: #35687d"&gt;$scores&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;sort&lt;/span&gt;
    
    &lt;span style="color: green"&gt;# Calclate avg skiping first and last&lt;/span&gt;
    &lt;span style="color: #35687d"&gt;$total&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;;
    &lt;span style="color: #35687d"&gt;$scores&lt;/span&gt;[&lt;span style="color: maroon"&gt;1&lt;/span&gt;..(&lt;span style="color: #35687d"&gt;$scores&lt;/span&gt;.Count - &lt;span style="color: maroon"&gt;2&lt;/span&gt;)] | &lt;span style="color: blue"&gt;foreach&lt;/span&gt; { &lt;span style="color: #35687d"&gt;$total&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$_&lt;/span&gt; }
    
    &lt;span style="color: #35687d"&gt;$skaterScores&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$name&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;Add-Member&lt;/span&gt; -memberType NoteProperty -Name AvgScore -Value (&lt;span style="color: #35687d"&gt;$total&lt;/span&gt; / (&lt;span style="color: #35687d"&gt;$scores&lt;/span&gt;.Length - &lt;span style="color: maroon"&gt;2&lt;/span&gt;)) -passthru 
}

&lt;span style="color: green"&gt;# Rank the skaters by Avg Score&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$skaterScores&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$skaterScores&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;sort&lt;/span&gt; -descending AvgScore

&lt;span style="color: green"&gt;# Assign medals to the top three&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;;
&lt;span style="color: blue"&gt;foreach&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$medal&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; (&lt;span style="color: maroon"&gt;"Gold"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Silver"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Bronze"&lt;/span&gt;)) &lt;br&gt;{
    &lt;span style="color: #35687d"&gt;$skaterScores&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;] | &lt;span style="color: #2b91af"&gt;Add-Member&lt;/span&gt; -MemberType NoteProperty -Name Medal -Value &lt;span style="color: #35687d"&gt;$medal&lt;/span&gt;
    &lt;span style="color: green"&gt;# Simple Console output&lt;/span&gt;
    &lt;span style="color: green"&gt;#"$medal Medal: $($skaterScores[$i]), $($skaterScores[$i].AvgScore)";&lt;/span&gt;
    &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;++;
}
&lt;span style="color: green"&gt;# Powershell V2 Gridview output&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$skaterScores&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;Select&lt;/span&gt; Medal, @{Name=&lt;span style="color: maroon"&gt;"Name"&lt;/span&gt;; Expression={&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;}}, AvgScore | Out-GridView&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent3.mspx"&gt;Event 3: Instant (Runoff) Winner&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$voters&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;new-object&lt;/span&gt; System.Collections.ArrayList;

&lt;span style="color: green"&gt;# Collect the votes from the file&lt;/span&gt;
&lt;span style="color: blue"&gt;foreach&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$voteLine&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; &lt;span style="color: maroon"&gt;"c:\scripts\votes.txt"&lt;/span&gt;)) &lt;br&gt;{
    &lt;span style="color: #35687d"&gt;$vote&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;new-object&lt;/span&gt; System.Collections.ArrayList;    
    &lt;span style="color: #35687d"&gt;$vote&lt;/span&gt;.AddRange(&lt;span style="color: #35687d"&gt;$voteLine&lt;/span&gt; -split &lt;span style="color: maroon"&gt;","&lt;/span&gt;)
    [void]&lt;span style="color: #35687d"&gt;$voters&lt;/span&gt;.Add(&lt;span style="color: #35687d"&gt;$vote&lt;/span&gt;)
}

&lt;span style="color: blue"&gt;while&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$true&lt;/span&gt;)
{
    &lt;span style="color: #35687d"&gt;$voteCount&lt;/span&gt; = @{}
    
    &lt;span style="color: green"&gt;# Tally voting results&lt;/span&gt;
    &lt;span style="color: #35687d"&gt;$voters&lt;/span&gt; | % { &lt;span style="color: #35687d"&gt;$voteCount&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;[&lt;span style="color: maroon"&gt;0&lt;/span&gt;]] = &lt;span style="color: #35687d"&gt;$voteCount&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;[&lt;span style="color: maroon"&gt;0&lt;/span&gt;]] + &lt;span style="color: maroon"&gt;1&lt;/span&gt;; }
    
    &lt;span style="color: green"&gt;# Sort voting results&lt;/span&gt;
    &lt;span style="color: #35687d"&gt;$voteCount&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$voteCount&lt;/span&gt;.GetEnumerator() | &lt;span style="color: #2b91af"&gt;sort&lt;/span&gt; -descending Value
    
    &lt;span style="color: green"&gt;# Did the winner get more than 50% of the vote?&lt;/span&gt;
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$voteCount&lt;/span&gt;[&lt;span style="color: maroon"&gt;0&lt;/span&gt;].Value * &lt;span style="color: maroon"&gt;2&lt;/span&gt; -gt &lt;span style="color: #35687d"&gt;$voters&lt;/span&gt;.Count)
    {
        &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; (&lt;span style="color: maroon"&gt;"The winner is {0} with {1:P2} of the vote."&lt;/span&gt; -f &lt;span style="color: #35687d"&gt;$voteCount&lt;/span&gt;[&lt;span style="color: maroon"&gt;0&lt;/span&gt;].Name, (&lt;span style="color: #35687d"&gt;$voteCount&lt;/span&gt;[&lt;span style="color: maroon"&gt;0&lt;/span&gt;].Value / &lt;span style="color: #35687d"&gt;$voters&lt;/span&gt;.Count))
        &lt;span style="color: blue"&gt;break&lt;/span&gt;;
    }
    &lt;span style="color: blue"&gt;else&lt;/span&gt;
    {
        &lt;span style="color: green"&gt;# Clear out the candidate with losted number of votes&lt;/span&gt;
        &lt;span style="color: #35687d"&gt;$voters&lt;/span&gt; | % { &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Remove(&lt;span style="color: #35687d"&gt;$voteCount&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$voteCount&lt;/span&gt;.Count - &lt;span style="color: maroon"&gt;1&lt;/span&gt;].Name); }
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent4.mspx"&gt;Event 4: Image is Everything&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -nonewline &lt;span style="color: maroon"&gt;"Enter month (M/YYYY): "&lt;/span&gt;
[DateTime]&lt;span style="color: #35687d"&gt;$month&lt;/span&gt; = (&lt;span style="color: #2b91af"&gt;Read-Host&lt;/span&gt;)

&lt;span style="color: green"&gt;# Ensure we are set to the first day of the month&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$month&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$month&lt;/span&gt;.AddDays(-&lt;span style="color: maroon"&gt;1&lt;/span&gt; * (&lt;span style="color: #35687d"&gt;$month&lt;/span&gt;.Day - &lt;span style="color: maroon"&gt;1&lt;/span&gt;)) 

&lt;span style="color: green"&gt;# Write month header&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: #35687d"&gt;$month&lt;/span&gt;.ToString(&lt;span style="color: maroon"&gt;"`n   MMMM yyyy`n"&lt;/span&gt;)

&lt;span style="color: green"&gt;# Write days of week headers&lt;/span&gt;
&lt;span style="color: maroon"&gt;0&lt;/span&gt;.&lt;span style="color: maroon"&gt;.6&lt;/span&gt; | % { &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -nonewline (&lt;span style="color: maroon"&gt;"{0,6}"&lt;/span&gt; -f ([string][DayofWeek]&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;).SubString(&lt;span style="color: maroon"&gt;0&lt;/span&gt;, &lt;span style="color: maroon"&gt;3&lt;/span&gt;)) }

&lt;span style="color: green"&gt;# Figure out the date of the first monday in a set of weeks&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$next&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$month&lt;/span&gt;.AddDays(-&lt;span style="color: maroon"&gt;1&lt;/span&gt; * [int]&lt;span style="color: #35687d"&gt;$month&lt;/span&gt;.DayofWeek)
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt;
&lt;span style="color: blue"&gt;while&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$next&lt;/span&gt;.Month -le &lt;span style="color: #35687d"&gt;$month&lt;/span&gt;.Month)
{
    &lt;span style="color: green"&gt;# Walk the week and only write the day if the mondy matches&lt;/span&gt;
    &lt;span style="color: maroon"&gt;0&lt;/span&gt;.&lt;span style="color: maroon"&gt;.6&lt;/span&gt; | &lt;span style="color: blue"&gt;foreach&lt;/span&gt; { 
        &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$next&lt;/span&gt;.Month -eq &lt;span style="color: #35687d"&gt;$month&lt;/span&gt;.Month) { &lt;span style="color: #35687d"&gt;$day&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$next&lt;/span&gt;.Day } &lt;span style="color: blue"&gt;else&lt;/span&gt; { &lt;span style="color: #35687d"&gt;$day&lt;/span&gt; = &lt;span style="color: maroon"&gt;""&lt;/span&gt; }
        &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -nonewline (&lt;span style="color: maroon"&gt;"{0,6}"&lt;/span&gt; -f &lt;span style="color: #35687d"&gt;$day&lt;/span&gt;)
        &lt;span style="color: #35687d"&gt;$next&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$next&lt;/span&gt;.AddDays(&lt;span style="color: maroon"&gt;1&lt;/span&gt;) 
    }
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt;
}
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent5.mspx"&gt;Event 5: You Call That a Strong Password?&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;param([string]&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt;)

&lt;span style="color: #35687d"&gt;$strength&lt;/span&gt; = &lt;span style="color: maroon"&gt;13&lt;/span&gt;

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Testing password [$pass]..."&lt;/span&gt;

&lt;span style="color: #35687d"&gt;$wl&lt;/span&gt; = (&lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; &lt;span style="color: maroon"&gt;"C:\Scripts\wordlist.txt"&lt;/span&gt;);

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$wl&lt;/span&gt; -contains &lt;span style="color: #35687d"&gt;$pass&lt;/span&gt;) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password is not an actual word."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$wl&lt;/span&gt; -contains &lt;span style="color: #35687d"&gt;$pass&lt;/span&gt;.SubString(&lt;span style="color: maroon"&gt;0&lt;/span&gt;,&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt;.Length-&lt;span style="color: maroon"&gt;1&lt;/span&gt;)) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password, minus the last letter, is not an actual word."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$wl&lt;/span&gt; -contains &lt;span style="color: #35687d"&gt;$pass&lt;/span&gt;.SubString(&lt;span style="color: maroon"&gt;1&lt;/span&gt;)) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password, minus the first letter, is not an actual word."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -match &lt;span style="color: maroon"&gt;"0"&lt;/span&gt; -and &lt;span style="color: #35687d"&gt;$wl&lt;/span&gt; -contains (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -replace &lt;span style="color: maroon"&gt;'0'&lt;/span&gt;,&lt;span style="color: maroon"&gt;'o'&lt;/span&gt;)) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password does not simply substitute 0 (zero) for the letter o (either an uppercase O or a lowercase o)."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -match &lt;span style="color: maroon"&gt;"1"&lt;/span&gt; -and &lt;span style="color: #35687d"&gt;$wl&lt;/span&gt; -contains (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -replace &lt;span style="color: maroon"&gt;'1'&lt;/span&gt;,&lt;span style="color: maroon"&gt;'l'&lt;/span&gt;)) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password does not simply substitute 1 (one) for the letter l (either an uppercase L or a lowercase l)."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt;.Length -lt &lt;span style="color: maroon"&gt;10&lt;/span&gt; -or &lt;span style="color: #35687d"&gt;$pass&lt;/span&gt;.Length -gt &lt;span style="color: maroon"&gt;20&lt;/span&gt;) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password is at least 10 characters long but no more than 20 characters long."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -notmatch &lt;span style="color: maroon"&gt;"\d"&lt;/span&gt;) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password includes at least one number (the digits 0 through 9)."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -cnotmatch &lt;span style="color: maroon"&gt;"[A-Z]"&lt;/span&gt;) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password includes at least one uppercase letter."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -cnotmatch &lt;span style="color: maroon"&gt;"[a-z]"&lt;/span&gt;) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password includes at least one lowercase letter."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -notmatch &lt;span style="color: maroon"&gt;"[^a-zA-Z0-9]"&lt;/span&gt;) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password includes at least one symbol."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -cmatch &lt;span style="color: maroon"&gt;"[a-z]{4}"&lt;/span&gt;) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password does not include four (or more) lowercase letters in succession."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -cmatch &lt;span style="color: maroon"&gt;"[A-Z]{4}"&lt;/span&gt;) {  
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password does not include four (or more) uppercase letters in succession."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pass&lt;/span&gt; -cmatch &lt;span style="color: maroon"&gt;"(.).*\1"&lt;/span&gt;) { 
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -f red &lt;span style="color: maroon"&gt;"Make sure that the password does not include any duplicate characters."&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$strength&lt;/span&gt;-- }

&lt;span style="color: #35687d"&gt;$s&lt;/span&gt; = &lt;span style="color: maroon"&gt;"moderately-strong"&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; = &lt;span style="color: maroon"&gt;"yellow"&lt;/span&gt;
&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$strength&lt;/span&gt; -le &lt;span style="color: maroon"&gt;6&lt;/span&gt;) { &lt;span style="color: #35687d"&gt;$s&lt;/span&gt; = &lt;span style="color: maroon"&gt;"weak"&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; = &lt;span style="color: maroon"&gt;"red"&lt;/span&gt; }
&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$strength&lt;/span&gt; -ge &lt;span style="color: maroon"&gt;11&lt;/span&gt;) { &lt;span style="color: #35687d"&gt;$s&lt;/span&gt; = &lt;span style="color: maroon"&gt;"strong"&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; = &lt;span style="color: maroon"&gt;"green"&lt;/span&gt; }

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -nonewline &lt;span style="color: maroon"&gt;"A password score of "&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -nonewline -f &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; &lt;span style="color: maroon"&gt;"$strength"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -nonewline &lt;span style="color: maroon"&gt;"/13 indicates a "&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -nonewline -f &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; &lt;span style="color: maroon"&gt;"$s"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;" password."&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent6.mspx"&gt;Event 6: Prime Time&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$primes&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;new-object&lt;/span&gt; System.Collections.ArrayList 
&lt;span style="color: #35687d"&gt;$primes&lt;/span&gt;.AddRange(&lt;span style="color: maroon"&gt;2&lt;/span&gt;.&lt;span style="color: maroon"&gt;.199&lt;/span&gt;)
&lt;span style="color: blue"&gt;for&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$primes&lt;/span&gt;.Count; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;++)
{
    &lt;span style="color: blue"&gt;for&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$j&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$i&lt;/span&gt; + &lt;span style="color: maroon"&gt;1&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$j&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$primes&lt;/span&gt;.Count;)
    {
        &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$primes&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$j&lt;/span&gt;] % &lt;span style="color: #35687d"&gt;$primes&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;] -eq &lt;span style="color: maroon"&gt;0&lt;/span&gt;)
        {
            &lt;span style="color: #35687d"&gt;$primes&lt;/span&gt;.Remove(&lt;span style="color: #35687d"&gt;$primes&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$j&lt;/span&gt;])
        }
        &lt;span style="color: blue"&gt;else&lt;/span&gt;
        {
            &lt;span style="color: #35687d"&gt;$j&lt;/span&gt;++;
        }
    }
}
&lt;span style="color: green"&gt;# Simple Console Output&lt;/span&gt;
&lt;span style="color: green"&gt;#$primes&lt;/span&gt;

&lt;span style="color: green"&gt;# Powershell V2 GridView&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$primes&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;select&lt;/span&gt; @{ Name=&lt;span style="color: maroon"&gt;"Primes"&lt;/span&gt;; Expression={ &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.ToString() } } | Out-GridView&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent7.mspx"&gt;Event 7: Play Ball!&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$a&lt;/span&gt; = &lt;span style="color: maroon"&gt;"A"&lt;/span&gt;,&lt;span style="color: maroon"&gt;"B"&lt;/span&gt;,&lt;span style="color: maroon"&gt;"C"&lt;/span&gt;,&lt;span style="color: maroon"&gt;"D"&lt;/span&gt;,&lt;span style="color: maroon"&gt;"E"&lt;/span&gt;,&lt;span style="color: maroon"&gt;"F"&lt;/span&gt;
&lt;span style="color: maroon"&gt;1&lt;/span&gt;..(&lt;span style="color: #35687d"&gt;$a&lt;/span&gt;.Length-&lt;span style="color: maroon"&gt;1&lt;/span&gt;) | % { ( &lt;span style="color: maroon"&gt;1&lt;/span&gt;..(&lt;span style="color: #35687d"&gt;$a&lt;/span&gt;.Length/&lt;span style="color: maroon"&gt;2&lt;/span&gt;) | % { &lt;span style="color: #35687d"&gt;$a&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;-&lt;span style="color: maroon"&gt;1&lt;/span&gt;]+&lt;span style="color: maroon"&gt;" vs. "&lt;/span&gt;+&lt;span style="color: #35687d"&gt;$a&lt;/span&gt;[-&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;] } ); &lt;span style="color: #2b91af"&gt;write-host&lt;/span&gt;; [string[]]&lt;span style="color: #35687d"&gt;$x&lt;/span&gt;,&lt;span style="color: #35687d"&gt;$y&lt;/span&gt;,&lt;span style="color: #35687d"&gt;$z&lt;/span&gt;=&lt;span style="color: #35687d"&gt;$a&lt;/span&gt;;&lt;span style="color: #35687d"&gt;$a&lt;/span&gt;=&lt;span style="color: #35687d"&gt;$x&lt;/span&gt;+&lt;span style="color: #35687d"&gt;$z&lt;/span&gt;+&lt;span style="color: #35687d"&gt;$y&lt;/span&gt;; }
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent8.mspx"&gt;Event 8: Making Beautiful Music&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$songs&lt;/span&gt;=@()
&lt;span style="color: #35687d"&gt;$names&lt;/span&gt;=@{}
&lt;span style="color: #35687d"&gt;$total&lt;/span&gt;=&lt;span style="color: maroon"&gt;0&lt;/span&gt;;
&lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$songLine&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; &lt;span style="color: maroon"&gt;"c:\scripts\songlist.csv"&lt;/span&gt;))
{
  &lt;span style="color: #35687d"&gt;$name&lt;/span&gt;,&lt;span style="color: #35687d"&gt;$title&lt;/span&gt;,&lt;span style="color: #35687d"&gt;$length&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$songLine&lt;/span&gt;.Split(&lt;span style="color: maroon"&gt;","&lt;/span&gt;);
  
  &lt;span style="color: green"&gt;# Ensure no more than 2 of same artist&lt;/span&gt;
  &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$names&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$name&lt;/span&gt;] -ge &lt;span style="color: maroon"&gt;2&lt;/span&gt;) { &lt;span style="color: blue"&gt;continue&lt;/span&gt; } &lt;span style="color: #35687d"&gt;$names&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$name&lt;/span&gt;]++;
  
  &lt;span style="color: #35687d"&gt;$mm&lt;/span&gt;,&lt;span style="color: #35687d"&gt;$ss&lt;/span&gt;=[int[]]&lt;span style="color: #35687d"&gt;$length&lt;/span&gt;.Split(&lt;span style="color: maroon"&gt;":"&lt;/span&gt;);
  &lt;span style="color: #35687d"&gt;$time&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$mm&lt;/span&gt;*&lt;span style="color: maroon"&gt;60&lt;/span&gt;+&lt;span style="color: #35687d"&gt;$ss&lt;/span&gt;;

  &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$total&lt;/span&gt; + &lt;span style="color: #35687d"&gt;$time&lt;/span&gt; -ge &lt;span style="color: maroon"&gt;4800&lt;/span&gt;) &lt;span style="color: green"&gt;# 80 Mins&lt;/span&gt;
  {
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$total&lt;/span&gt; -gt &lt;span style="color: maroon"&gt;4500&lt;/span&gt;) { &lt;span style="color: blue"&gt;break&lt;/span&gt;; } &lt;span style="color: green"&gt;# Done&lt;/span&gt;
    &lt;span style="color: blue"&gt;continue&lt;/span&gt;; &lt;span style="color: green"&gt;# Try next song&lt;/span&gt;
  }
  &lt;span style="color: #35687d"&gt;$total&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$time&lt;/span&gt;;
    
  &lt;span style="color: #35687d"&gt;$song&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;new-object&lt;/span&gt; psobject
  &lt;span style="color: #35687d"&gt;$song&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;Add-Member&lt;/span&gt; NoteProperty &lt;span style="color: maroon"&gt;"Artist Name"&lt;/span&gt; &lt;span style="color: #35687d"&gt;$name&lt;/span&gt;
  &lt;span style="color: #35687d"&gt;$song&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;Add-Member&lt;/span&gt; NoteProperty &lt;span style="color: maroon"&gt;"Song Title"&lt;/span&gt;  &lt;span style="color: #35687d"&gt;$title&lt;/span&gt;
  &lt;span style="color: #35687d"&gt;$song&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;Add-Member&lt;/span&gt; NoteProperty &lt;span style="color: maroon"&gt;"Song Length"&lt;/span&gt; &lt;span style="color: #35687d"&gt;$length&lt;/span&gt;
  &lt;span style="color: #35687d"&gt;$songs&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$song&lt;/span&gt;
}

&lt;span style="color: #35687d"&gt;$songs&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;sort&lt;/span&gt; &lt;span style="color: maroon"&gt;"Artist Name"&lt;/span&gt;

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; (&lt;span style="color: maroon"&gt;"`nTotal music time: {0}:{1:00}"&lt;/span&gt; -f ((&lt;span style="color: #35687d"&gt;$total&lt;/span&gt;-&lt;span style="color: #35687d"&gt;$total&lt;/span&gt;&lt;span style="color: #2b91af"&gt;%&lt;/span&gt;&lt;span style="color: maroon"&gt;60&lt;/span&gt;)/&lt;span style="color: maroon"&gt;60&lt;/span&gt;), (&lt;span style="color: #35687d"&gt;$total&lt;/span&gt;&lt;span style="color: #2b91af"&gt;%&lt;/span&gt;&lt;span style="color: maroon"&gt;60&lt;/span&gt;))&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent9.mspx"&gt;Event 9: You’re Twisting My Words&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;((&lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; &lt;span style="color: maroon"&gt;"c:\scripts\alice.txt"&lt;/span&gt;) -split &lt;span style="color: maroon"&gt;"\s"&lt;/span&gt; | % { &lt;span style="color: #35687d"&gt;$s&lt;/span&gt;=[char[]]&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;; [System.Array]::Reverse(&lt;span style="color: #35687d"&gt;$s&lt;/span&gt;); &lt;span style="color: #35687d"&gt;$s&lt;/span&gt; -join &lt;span style="color: maroon"&gt;""&lt;/span&gt; }) -join &lt;span style="color: maroon"&gt;" "&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/aevent10.mspx"&gt;Event 10: Blackjack!&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$suites&lt;/span&gt; = &lt;span style="color: maroon"&gt;"Clubs"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Diamonds"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Hearts"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Spades"&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$numStrings&lt;/span&gt; = &lt;span style="color: maroon"&gt;"Ace"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Two"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Three"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Four"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Five"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Six"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Seven"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Eight"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Nine"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Ten"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Jack"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"Queen"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"King"&lt;/span&gt;

&lt;span style="color: blue"&gt;function&lt;/span&gt; NextCard { &lt;span style="color: #35687d"&gt;$c&lt;/span&gt;,&lt;span style="color: #35687d"&gt;$script&lt;/span&gt;:cards = &lt;span style="color: #35687d"&gt;$script&lt;/span&gt;:cards; &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; }
&lt;span style="color: blue"&gt;function&lt;/span&gt; ShowYourCards { 
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"`nYour cards:"&lt;/span&gt;
    &lt;span style="color: #35687d"&gt;$script&lt;/span&gt;:yourSum = &lt;span style="color: maroon"&gt;0&lt;/span&gt;;
    &lt;span style="color: #35687d"&gt;$aces&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;;
    &lt;span style="color: #35687d"&gt;$yourCards&lt;/span&gt; | % { &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Value -eq &lt;span style="color: maroon"&gt;11&lt;/span&gt;) { &lt;span style="color: #35687d"&gt;$aces&lt;/span&gt;++ }; &lt;span style="color: #35687d"&gt;$script&lt;/span&gt;:yourSum += &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Value; &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Name }
    &lt;span style="color: blue"&gt;while&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$script&lt;/span&gt;:yourSum -gt &lt;span style="color: maroon"&gt;21&lt;/span&gt; -and &lt;span style="color: #35687d"&gt;$aces&lt;/span&gt; -gt &lt;span style="color: maroon"&gt;0&lt;/span&gt;) { &lt;span style="color: #35687d"&gt;$script&lt;/span&gt;:yourSum -= &lt;span style="color: maroon"&gt;10&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$aces&lt;/span&gt;--; }
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Your card total is $yourSum"&lt;/span&gt;
}
&lt;span style="color: blue"&gt;function&lt;/span&gt; ShowDealerCards {
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"`nDealer's cards:"&lt;/span&gt;
    &lt;span style="color: #35687d"&gt;$script&lt;/span&gt;:dealerSum = &lt;span style="color: maroon"&gt;0&lt;/span&gt;
    &lt;span style="color: #35687d"&gt;$aces&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;;
    &lt;span style="color: #35687d"&gt;$dealerCards&lt;/span&gt;  | % { &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Value -eq &lt;span style="color: maroon"&gt;11&lt;/span&gt;) { &lt;span style="color: #35687d"&gt;$aces&lt;/span&gt;++ }; &lt;span style="color: #35687d"&gt;$script&lt;/span&gt;:dealerSum += &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Value; &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Name }
    &lt;span style="color: blue"&gt;while&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$script&lt;/span&gt;:dealerSum -gt &lt;span style="color: maroon"&gt;21&lt;/span&gt; -and &lt;span style="color: #35687d"&gt;$aces&lt;/span&gt; -gt &lt;span style="color: maroon"&gt;0&lt;/span&gt;) { &lt;span style="color: #35687d"&gt;$script&lt;/span&gt;:dealerSum -= &lt;span style="color: maroon"&gt;10&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$aces&lt;/span&gt;--; }
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Dealer card total is $dealerSum"&lt;/span&gt;
}
&lt;span style="color: blue"&gt;function&lt;/span&gt; Outcome([bool]&lt;span style="color: #35687d"&gt;$win&lt;/span&gt;, [string]&lt;span style="color: #35687d"&gt;$msg&lt;/span&gt;) {
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$win&lt;/span&gt;) {
        &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -ForegroundColor green &lt;span style="color: maroon"&gt;"`nYou win! $msg"&lt;/span&gt;
    }
    &lt;span style="color: blue"&gt;else&lt;/span&gt; {
        &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -ForegroundColor red &lt;span style="color: maroon"&gt;"`nYou lose! $msg"&lt;/span&gt;
    }
    exit
}

&lt;span style="color: #35687d"&gt;$cards&lt;/span&gt; = @()
&lt;span style="color: blue"&gt;foreach&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$suite&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: #35687d"&gt;$suites&lt;/span&gt;) {
    &lt;span style="color: blue"&gt;for&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$numStrings&lt;/span&gt;.Count; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;++)              {
        &lt;span style="color: #35687d"&gt;$numStr&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$numStrings&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;];
        &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;New-Object&lt;/span&gt; PsObject
        &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;Add-Member&lt;/span&gt; NoteProperty Name $(&lt;span style="color: #35687d"&gt;$numStr&lt;/span&gt; + &lt;span style="color: maroon"&gt;" of "&lt;/span&gt; + &lt;span style="color: #35687d"&gt;$suite&lt;/span&gt;)
        &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;Add-Member&lt;/span&gt; NoteProperty Value $(&lt;span style="color: blue"&gt;if&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; -gt &lt;span style="color: maroon"&gt;9&lt;/span&gt;){&lt;span style="color: maroon"&gt;10&lt;/span&gt;}&lt;span style="color: blue"&gt;else&lt;/span&gt;{&lt;span style="color: blue"&gt;if&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; -eq &lt;span style="color: maroon"&gt;0&lt;/span&gt;){&lt;span style="color: maroon"&gt;11&lt;/span&gt;}&lt;span style="color: blue"&gt;else&lt;/span&gt;{&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;+&lt;span style="color: maroon"&gt;1&lt;/span&gt;}})
        &lt;span style="color: #35687d"&gt;$cards&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$c&lt;/span&gt;
    }
}

&lt;span style="color: #35687d"&gt;$rand&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;New-Object&lt;/span&gt; Random
&lt;span style="color: #35687d"&gt;$cards&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$cards&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;sort&lt;/span&gt; { &lt;span style="color: #35687d"&gt;$rand&lt;/span&gt;.Next() }

&lt;span style="color: #35687d"&gt;$yourCards&lt;/span&gt; = @()
&lt;span style="color: #35687d"&gt;$dealerCards&lt;/span&gt; = @()

&lt;span style="color: #35687d"&gt;$yourCards&lt;/span&gt; += NextCard
&lt;span style="color: #35687d"&gt;$dealerCards&lt;/span&gt; += NextCard
&lt;span style="color: #35687d"&gt;$yourCards&lt;/span&gt; += NextCard

ShowYourCards
&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$yourSum&lt;/span&gt; -eq &lt;span style="color: maroon"&gt;21&lt;/span&gt;) {
    Outcome &lt;span style="color: #35687d"&gt;$true&lt;/span&gt; &lt;span style="color: maroon"&gt;"Blackjack, you got 21 with two cards."&lt;/span&gt;
}
ShowDealerCards
&lt;span style="color: #35687d"&gt;$dealerCards&lt;/span&gt; += NextCard
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; 
&lt;span style="color: blue"&gt;while&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$yourSum&lt;/span&gt; -lt &lt;span style="color: maroon"&gt;21&lt;/span&gt;) {
    &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; -NoNewline &lt;span style="color: maroon"&gt;"Stay (s) or hit (h)? "&lt;/span&gt;
    &lt;span style="color: #35687d"&gt;$hitOrStay&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;Read-Host&lt;/span&gt;
    
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$hitOrStay&lt;/span&gt; -ieq &lt;span style="color: maroon"&gt;"s"&lt;/span&gt;) { &lt;span style="color: blue"&gt;break&lt;/span&gt;; }
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$hitOrStay&lt;/span&gt; -ieq &lt;span style="color: maroon"&gt;"h"&lt;/span&gt;)
    {
        &lt;span style="color: #35687d"&gt;$yourCards&lt;/span&gt; += NextCard
        ShowYourCards
    }
}
&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$yourSum&lt;/span&gt; -gt &lt;span style="color: maroon"&gt;21&lt;/span&gt;) {
    Outcome &lt;span style="color: #35687d"&gt;$false&lt;/span&gt; &lt;span style="color: maroon"&gt;"Your total $yourSum is over 21."&lt;/span&gt;
}
&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$yourSum&lt;/span&gt; -eq &lt;span style="color: maroon"&gt;21&lt;/span&gt;) {
    Outcome &lt;span style="color: #35687d"&gt;$true&lt;/span&gt; &lt;span style="color: maroon"&gt;"Your total is exactly 21."&lt;/span&gt;
}
ShowDealerCards
&lt;span style="color: green"&gt;# Assumes dealer keeps hitting while he is losing and not over 21, unlike most casinos where the stop at 17&lt;/span&gt;
&lt;span style="color: blue"&gt;while&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$dealerSum&lt;/span&gt; -lt &lt;span style="color: maroon"&gt;21&lt;/span&gt; -and &lt;span style="color: #35687d"&gt;$dealerSum&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$yourSum&lt;/span&gt;) {
    &lt;span style="color: #35687d"&gt;$dealerCards&lt;/span&gt; += NextCard
    ShowDealerCards
}
&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$dealerSum&lt;/span&gt; -gt &lt;span style="color: maroon"&gt;21&lt;/span&gt;) {
    Outcome &lt;span style="color: #35687d"&gt;$true&lt;/span&gt; &lt;span style="color: maroon"&gt;"Dealer busted because dealer's $dealerSum is over 21."&lt;/span&gt;
}
&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$dealerSum&lt;/span&gt; -ge &lt;span style="color: #35687d"&gt;$yourSum&lt;/span&gt;) {
    Outcome &lt;span style="color: #35687d"&gt;$false&lt;/span&gt; &lt;span style="color: maroon"&gt;"The dealer's $dealerSum is greater than or equal to your $yourSum."&lt;/span&gt;
}
&lt;span style="color: blue"&gt;else&lt;/span&gt; {
    Outcome &lt;span style="color: #35687d"&gt;$true&lt;/span&gt; &lt;span style="color: maroon"&gt;"Your $yourSum is geater than the dealer's $dealerSum."&lt;/span&gt;
}&lt;/pre&gt;
&lt;h2&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdhome.mspx"&gt;Sudden death challenge&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdevent1.mspx"&gt;Event 1: Could I See Some ProgID, Please?&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/sdsol01.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: green"&gt;#-1. Enables you to manage the Windows Firewall in Windows XP.&lt;/span&gt;
&lt;span style="color: green"&gt;# 2. Enables you to create a remote connection using Windows Script Host.&lt;/span&gt;
&lt;span style="color: green"&gt;#-3. Enables you to map printers using Windows Script Host.&lt;/span&gt;
&lt;span style="color: green"&gt;# 4. Enables you to perform an XPath query in an XML document.&lt;/span&gt;
&lt;span style="color: green"&gt;# 5. Enables you to create an instance of Internet Explorer.&lt;/span&gt;
&lt;span style="color: green"&gt;#-6. Enables you to connect to a database.&lt;/span&gt;
&lt;span style="color: green"&gt;#-7. Enables you to perform text-to-speech conversions in a script. &lt;/span&gt;
&lt;span style="color: green"&gt;# 8. Enables you to create an instance of Microsoft Excel.&lt;/span&gt;
&lt;span style="color: green"&gt;#-9. Enables you to send and create SMTP email.&lt;/span&gt;
&lt;span style="color: green"&gt;#-10. Enables you to create an instance of Microsoft Outlook.&lt;/span&gt;
&lt;span style="color: green"&gt;#-11. Enables you to work with Windows Remote Management.&lt;/span&gt;
&lt;span style="color: green"&gt;# 12. Enables you to access type libraries from a script.&lt;/span&gt;
&lt;span style="color: green"&gt;#-13. Enables you to manage Microsoft Indexing Server.&lt;/span&gt;
&lt;span style="color: green"&gt;#-14. Enables you to manage Windows Media Player.&lt;/span&gt;
&lt;span style="color: green"&gt;# 15. Enables you to manage Windows Update Services.&lt;/span&gt;
&lt;span style="color: green"&gt;# 16. Enables you to manage TCP/IP and other network settings.&lt;/span&gt;
&lt;span style="color: green"&gt;#-17. Enables you to work with XML documents.&lt;/span&gt;
&lt;span style="color: green"&gt;# 18. Enables you to manage fonts.&lt;/span&gt;
&lt;span style="color: green"&gt;#-19. Enables you to create a GUID.&lt;/span&gt;
&lt;span style="color: green"&gt;#-20. Enables you to convert Active Directory names from one format to another.&lt;/span&gt;

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"ProgID              Description"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"ADODB.Connection              6"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"HNetCfg.FwMgr                 1"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Microsoft.XMLDOM             17"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"SAPI.SpVoice                  7"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"NameTranslate                20"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Scriptlet.TypeLib            19"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Outlook.Application          10"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"WMPlayer.OCX                 14"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"WScript.Network               3"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"WSMan.Automation             11"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"CDO.Application               9"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Microsoft.ISAdm              13"&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdevent2.mspx"&gt;Event 2: Typing Isn’t Really Our Thing&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/sdsol02.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$v&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;get-content&lt;/span&gt; c:\scripts\vertical.txt
&lt;span style="color: #35687d"&gt;$t&lt;/span&gt; = &lt;span style="color: maroon"&gt;""&lt;/span&gt;
&lt;span style="color: blue"&gt;for&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;=&lt;span style="color: maroon"&gt;0&lt;/span&gt;;&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$v&lt;/span&gt;[&lt;span style="color: maroon"&gt;0&lt;/span&gt;].Length; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;++){ &lt;span style="color: blue"&gt;for&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$j&lt;/span&gt;=&lt;span style="color: maroon"&gt;0&lt;/span&gt;;&lt;span style="color: #35687d"&gt;$j&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$v&lt;/span&gt;.Count; &lt;span style="color: #35687d"&gt;$j&lt;/span&gt;++) { &lt;span style="color: #35687d"&gt;$t&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$v&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$j&lt;/span&gt;][&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;] } }
&lt;span style="color: #35687d"&gt;$t&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdevent3.mspx"&gt;Event 3: What's in a Name?&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/sdsol03.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$pfile&lt;/span&gt; = (&lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; &lt;span style="color: maroon"&gt;"c:\Scripts\presidents.txt"&lt;/span&gt;)
&lt;span style="color: #35687d"&gt;$longestFirst&lt;/span&gt; = &lt;span style="color: maroon"&gt;""&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$vowelCount&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$alpha&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;New-Object&lt;/span&gt; System.Collections.ArrayList
&lt;span style="color: maroon"&gt;0&lt;/span&gt;.&lt;span style="color: maroon"&gt;.25&lt;/span&gt; | % { [void]&lt;span style="color: #35687d"&gt;$alpha&lt;/span&gt;.Add([char](&lt;span style="color: #35687d"&gt;$_&lt;/span&gt; + [int][char]&lt;span style="color: maroon"&gt;"A"&lt;/span&gt;)) }

&lt;span style="color: blue"&gt;foreach&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$pr&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: #35687d"&gt;$pfile&lt;/span&gt;)
{
    &lt;span style="color: #35687d"&gt;$last&lt;/span&gt;, &lt;span style="color: #35687d"&gt;$first&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$pr&lt;/span&gt;.Split(&lt;span style="color: maroon"&gt;","&lt;/span&gt;)
    &lt;span style="color: #35687d"&gt;$first&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$first&lt;/span&gt;.Trim()

    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$longestFirst&lt;/span&gt;.Length -lt &lt;span style="color: #35687d"&gt;$first&lt;/span&gt;.Length)
    {
        &lt;span style="color: #35687d"&gt;$longestFirst&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$first&lt;/span&gt;;
    }
    &lt;span style="color: #35687d"&gt;$alpha&lt;/span&gt;.Remove([Char]::ToUpper(&lt;span style="color: #35687d"&gt;$first&lt;/span&gt;[&lt;span style="color: maroon"&gt;0&lt;/span&gt;]))
    &lt;span style="color: #35687d"&gt;$alpha&lt;/span&gt;.Remove([Char]::ToUpper(&lt;span style="color: #35687d"&gt;$last&lt;/span&gt;[&lt;span style="color: maroon"&gt;0&lt;/span&gt;]))
    
    &lt;span style="color: #35687d"&gt;$pr&lt;/span&gt;.ToCharArray() | ? { &lt;span style="color: #35687d"&gt;$_&lt;/span&gt; -match &lt;span style="color: maroon"&gt;"[aeiouAEIOU]"&lt;/span&gt; } | % { &lt;span style="color: #35687d"&gt;$vowelCount&lt;/span&gt;++ }
}

&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Longest first name: $longestFirst"&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Letters not in initials:"&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$alpha&lt;/span&gt; | % { &lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: #35687d"&gt;$_&lt;/span&gt; }
&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"Total vowel count: $vowelCount"&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdevent4.mspx"&gt;Event 4: Type By Numbers&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/sdsol04.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$a&lt;/span&gt; = (&lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; &lt;span style="color: maroon"&gt;"C:\scripts\numbers.txt"&lt;/span&gt;)
&lt;span style="color: #35687d"&gt;$s&lt;/span&gt; = &lt;span style="color: maroon"&gt;""&lt;/span&gt;
&lt;span style="color: blue"&gt;for&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$i&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$a&lt;/span&gt;.Length; &lt;span style="color: #35687d"&gt;$i&lt;/span&gt;+=&lt;span style="color: maroon"&gt;2&lt;/span&gt;) { [int]&lt;span style="color: #35687d"&gt;$c&lt;/span&gt;=([string]::Join(&lt;span style="color: maroon"&gt;""&lt;/span&gt;,&lt;span style="color: #35687d"&gt;$a&lt;/span&gt;[(&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;)..(&lt;span style="color: #35687d"&gt;$i&lt;/span&gt;+&lt;span style="color: maroon"&gt;1&lt;/span&gt;)])); &lt;span style="color: #35687d"&gt;$s&lt;/span&gt; += [char]&lt;span style="color: #35687d"&gt;$c&lt;/span&gt; }
&lt;span style="color: #35687d"&gt;$s&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdevent5.mspx"&gt;Event 5: WMI From A to Z – er, A to Y&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/sdsol05.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$d&lt;/span&gt; = @{ }
&lt;span style="color: #35687d"&gt;$win32Classes&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;Get-WmiObject&lt;/span&gt; -namespace &lt;span style="color: maroon"&gt;"root\cimv2"&lt;/span&gt; -list | ? { &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Name -match &lt;span style="color: maroon"&gt;"^Win32_"&lt;/span&gt; } 

&lt;span style="color: blue"&gt;foreach&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$w&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: #35687d"&gt;$win32Classes&lt;/span&gt;)
{
    &lt;span style="color: blue"&gt;foreach&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$p&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: #35687d"&gt;$w&lt;/span&gt;.psbase.Properties)
    {
        &lt;span style="color: #35687d"&gt;$c&lt;/span&gt; = [char]::ToUpper(&lt;span style="color: #35687d"&gt;$p&lt;/span&gt;.Name[&lt;span style="color: maroon"&gt;0&lt;/span&gt;]);
        
        &lt;span style="color: blue"&gt;if&lt;/span&gt; ([char]::IsLetter(&lt;span style="color: #35687d"&gt;$c&lt;/span&gt;) -and !&lt;span style="color: #35687d"&gt;$d&lt;/span&gt;.ContainsKey(&lt;span style="color: #35687d"&gt;$c&lt;/span&gt;))
        {
            &lt;span style="color: #35687d"&gt;$p&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;Add-Member&lt;/span&gt; -MemberType NoteProperty -Name Property -Value &lt;span style="color: #35687d"&gt;$p&lt;/span&gt;.Name
            &lt;span style="color: #35687d"&gt;$p&lt;/span&gt; | &lt;span style="color: #2b91af"&gt;Add-Member&lt;/span&gt; -MemberType NoteProperty -Name Win32Class -Value &lt;span style="color: #35687d"&gt;$w&lt;/span&gt;.Name
            &lt;span style="color: #35687d"&gt;$d&lt;/span&gt;[&lt;span style="color: #35687d"&gt;$c&lt;/span&gt;] = &lt;span style="color: #35687d"&gt;$p&lt;/span&gt;
            &lt;span style="color: blue"&gt;break&lt;/span&gt;; // Lets only get one property from a given class
        }
    }
    &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$d&lt;/span&gt;.Count -eq &lt;span style="color: maroon"&gt;25&lt;/span&gt;) { &lt;span style="color: blue"&gt;break&lt;/span&gt;; }
}

&lt;span style="color: #35687d"&gt;$d&lt;/span&gt;.Values | &lt;span style="color: #2b91af"&gt;sort&lt;/span&gt; Property | &lt;span style="color: #2b91af"&gt;Select&lt;/span&gt; Property, Win32Class&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdevent6.mspx"&gt;Event 6: If at First You Don’t Succeed...&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/sdsol06.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$v&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;get-content&lt;/span&gt; c:\scripts\lettercase.txt
&lt;span style="color: #35687d"&gt;$t&lt;/span&gt;=&lt;span style="color: maroon"&gt;""&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$v&lt;/span&gt;.ToCharArray() | % {
    &lt;span style="color: blue"&gt;if&lt;/span&gt; ([char]::IsUpper(&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;)) { &lt;span style="color: #35687d"&gt;$t&lt;/span&gt; += [char]::ToLower(&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;) } &lt;span style="color: blue"&gt;else&lt;/span&gt; {
    &lt;span style="color: blue"&gt;if&lt;/span&gt; ([char]::IsLower(&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;)) { &lt;span style="color: #35687d"&gt;$t&lt;/span&gt; += [char]::ToUpper(&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;) } &lt;span style="color: blue"&gt;else&lt;/span&gt; {
    &lt;span style="color: blue"&gt;if&lt;/span&gt; ([char]::IsDigit(&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;)) { &lt;span style="color: #35687d"&gt;$t&lt;/span&gt; += [int][char]&lt;span style="color: #35687d"&gt;$_&lt;/span&gt;-&lt;span style="color: maroon"&gt;49&lt;/span&gt; } &lt;span style="color: blue"&gt;else&lt;/span&gt; {
        &lt;span style="color: #35687d"&gt;$t&lt;/span&gt; += &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;;
    } } }
}
&lt;span style="color: #35687d"&gt;$t&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdevent7.mspx"&gt;Event 7: Simon Says "Multiply By 4"&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/sdsol07.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;span style="color: #35687d"&gt;$val&lt;/span&gt; = &lt;span style="color: maroon"&gt;"{0:F2}"&lt;/span&gt; -f ([Math]::Sqrt([Math]::Pow([Math]::Floor((&lt;span style="color: maroon"&gt;100&lt;/span&gt; * &lt;span style="color: maroon"&gt;2&lt;/span&gt;) / &lt;span style="color: maroon"&gt;30&lt;/span&gt;), &lt;span style="color: maroon"&gt;5&lt;/span&gt;) * &lt;span style="color: maroon"&gt;4&lt;/span&gt;) / &lt;span style="color: maroon"&gt;45&lt;/span&gt;)
&lt;span style="color: #35687d"&gt;$voice&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;new-object&lt;/span&gt; -com SAPI.SpVoice
[void]&lt;span style="color: #35687d"&gt;$voice&lt;/span&gt;.Speak(&lt;span style="color: #35687d"&gt;$val&lt;/span&gt;)&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdevent8.mspx"&gt;Event 8: The Display’s the Thing&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/sdsol08.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;&lt;strong&gt;Value               LDAP Display Name&lt;/strong&gt;
Kenneth             givenName
J                   initials
Myer                sn
712 NE 40th Way     streetAddress
Redmond             l
WA                  st
98052               postalCode
USA                 c
1-425-555-1234      telephoneNumber
kmyer@fabrikam.com  mail&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdevent9.mspx"&gt;Event 9: The Third Time Was Not a Charm&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/sdsol09.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;(&lt;span style="color: #2b91af"&gt;Get-Content&lt;/span&gt; c:\scripts\symbols.txt) -replace &lt;span style="color: maroon"&gt;"[^\da-z ]"&lt;/span&gt;,&lt;span style="color: maroon"&gt;""&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/sdevent10.mspx"&gt;Event 10: Triple Word Scramble&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/sdsol10.mspx"&gt;Official Solution&lt;/a&gt;&lt;br&gt;My Solution:&lt;/p&gt;&lt;pre style="background-color: lightgrey"&gt;.CSRIIEHRRTOENSWWPOCTIHPT-T

Wscript.Echo
Write-Host
Print&lt;/pre&gt;</description><pubDate>Mon, 10 Mar 2008 06:23:56 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/2008-scripting-games-my-solutions</guid><category>.NET</category><category>Code</category><category>Powershell</category><category>Tips and Tricks</category></item><item><title>2008 Scripting Games</title><link>https://weblogs.asp.net:443/whaggard/2008-scripting-games</link><description>&lt;p&gt;It’s the third annual &lt;a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/default.mspx"&gt;Scripting Games&lt;/a&gt;, the biggest scripting competition of the year! As a matter of fact, it’s most likely the biggest scripting competition &lt;i&gt;ever&lt;/i&gt;. (The fact that it may be the &lt;i&gt;only&lt;/i&gt; scripting competition is beside the point.)&lt;/p&gt; &lt;p&gt;The games have already begun on Feb 15 but you have until 8 AM Feb 20 to submit the solutions for the first two events. &lt;p&gt;If you want to force yourself to learn Powershell (or Perl or VBScript) then I would suggest having a look. Even though I'm not eligible for prizes because I'm a Microsoft employee, I plan on participating to help fill in the gaps of my Powershell skills. I may also try to post my solutions (after the deadline of course :)).&lt;/p&gt;</description><pubDate>Sun, 17 Feb 2008 05:27:21 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/2008-scripting-games</guid><category>.NET</category><category>News</category><category>Powershell</category></item><item><title>All Outlook object model calls run on the main thread</title><link>https://weblogs.asp.net:443/whaggard/all-outlook-object-model-calls-run-on-the-main-thread</link><description>&lt;p&gt;While writing an Outlook addin, lots of people feel that they should try to help with Outlook performance by running their addin code on a background thread. While this can help in some scenarios it can actually make things worse in others, particularly if the addin is interacting primarily with the Outlook Object Model (OOM). The OOM is run in a &lt;a href="http://msdn.microsoft.com/en-us/library/ms680112.aspx"&gt;single threaded apartment&lt;/a&gt; COM server, therefore every COM call is executed on the main thread of outlook.exe. &lt;/p&gt; &lt;p&gt;If an addin is interacting with the OOM from another apartment (i.e. on a background thread or another process) all the calls have to be marshaled to and from the server apartment (i.e. the main thread) which causes some extra overhead. This overhead is why working on a background thread could actually make performance worse and it does not exist if the addin is executing in the same apartment.&lt;/p&gt; &lt;p&gt;Like most things, it is a balancing act and one needs to find the proper balance for their particular situation. Just remember the key to performance is &lt;a href="http://blogs.msdn.com/ricom/archive/2007/06/13/partly-sunny-chance-of-showers-bring-an-umbrella.aspx"&gt;"Measure, Measure, Measure..."&lt;/a&gt;&lt;/p&gt;</description><pubDate>Tue, 05 Feb 2008 06:12:52 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/all-outlook-object-model-calls-run-on-the-main-thread</guid><category>Code</category><category>Outlook</category><category>Tips and Tricks</category></item><item><title>Issues with the XmlSerializer in medium trust environments</title><link>https://weblogs.asp.net:443/whaggard/issues-with-the-xmlserializer-in-medium-trust-environments</link><description>&lt;p&gt;In my last &lt;a href="http://weblogs.asp.net/whaggard/archive/2008/01/14/added-codehtmler-project-at-codeplex.aspx"&gt;post&lt;/a&gt; I briefly mentioned that &lt;a href="http://codeplex.com/CodeHtmler"&gt;CodeHTMLer&lt;/a&gt; had issues running in a medium trust environment. The simple web application front end I created kept failing before it ever got started. It keep hitting a SecurityException nested in an InvalidOperationException which looks something like:&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New"&gt;[Exception: System.InvalidOperationException: There was an error reflecting type 'CodeHtmler.Languages'. ---&amp;gt; System.Security.SecurityException: Request failed.&lt;br&gt;&amp;nbsp;&amp;nbsp; at System.Reflection.CustomAttribute._CreateCaObject(...)&lt;br&gt;&amp;nbsp;&amp;nbsp; at System.Reflection.CustomAttribute.CreateCaObject(...)&lt;br&gt;&amp;nbsp;&amp;nbsp; at System.Reflection.CustomAttribute.GetCustomAttributes(...)&lt;br&gt;&amp;nbsp;&amp;nbsp; at System.Reflection.CustomAttribute.GetCustomAttributes(...)&lt;br&gt;&amp;nbsp;&amp;nbsp; at System.Reflection.RuntimePropertyInfo.GetCustomAttributes(...)&lt;br&gt;&amp;nbsp;&amp;nbsp; at System.Xml.Serialization.XmlAttributes..ctor(...)&lt;br&gt;&amp;nbsp;&amp;nbsp; at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(...)&lt;br&gt;&amp;nbsp;&amp;nbsp; at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(...)&lt;br&gt;The action that failed was:&lt;br&gt;InheritanceDemand&lt;br&gt;The type of the first permission that failed was:&lt;br&gt;System.Security.PermissionSet&lt;br&gt;The Zone of the assembly that failed was:&lt;br&gt;MyComputer&lt;/font&gt; &lt;p&gt;&lt;a href="http://codeplex.com/CodeHtmler"&gt;CodeHTMLer&lt;/a&gt; uses the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;XmlSerializer&lt;/a&gt; to read and write the language definitions and it appeared to be what was causing this exceptions to be thrown. I spent a good deal of time trying to figure out why this wasn't working because every thing I read online said the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;XmlSerializer&lt;/a&gt; should actually work in medium trust. After a while of debugging I finally figured out that the problem was caused by some custom attributes.&lt;pre&gt;[XmlAttribute]
[Editor(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(HtmlColorEditor), &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(System.Drawing.Design.UITypeEditor))]
&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; Color {...}&lt;/pre&gt;
&lt;p&gt;Apparently when the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;XmlSerializer&lt;/a&gt; is walking through the custom attributes it runs into the &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.editorattribute.aspx"&gt;EditorAttribute&lt;/a&gt; and then tries to get the type of my custom editor HtmlColorEditor which has &lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.design.uitypeeditor.aspx"&gt;UITypeEditor&lt;/a&gt; in it's inheritance chain. However &lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.design.uitypeeditor.aspx"&gt;UITypeEditor&lt;/a&gt; for some reason demands a FullTrust permission set for Inheritance, which is problematic in a medium trust environment. To verify for certain that this was the issue I removed those editor attributes and then the XML serialization worked as expected under medium trust.&lt;/p&gt;
&lt;p&gt;Those editor attributes are used by the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.propertygrid.aspx"&gt;PropertyGrid&lt;/a&gt;, which is my lame way of providing UI to edit the language definitions, so I didn't want to remove them permanently but I also wanted the serialization to work in a medium trust environment. To allow for both the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.propertygrid.aspx"&gt;PropertyGrid&lt;/a&gt; and the medium trust serialization to work I decided to use the &lt;a href="http://msdn.microsoft.com/en-us/library/bk3w6240(vs.80).aspx"&gt;sgen&lt;/a&gt; tool to generate the serialization classes statically when I knew I had FullTrust permissions, instead of dynamically at runtime like the generic &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;XmlSerializer&lt;/a&gt; class does. &lt;/p&gt;
&lt;p&gt;The output of &lt;a href="http://msdn.microsoft.com/en-us/library/bk3w6240(vs.80).aspx"&gt;sgen&lt;/a&gt; was another assembly, &lt;font face="Courier New"&gt;CodeHtmler.XmlSerializers.dll&lt;/font&gt; which I then needed to reference and switch the code from using the more general &lt;font face="Courier New"&gt;XmlSerializer(typeof(Languages))&lt;/font&gt; to the specific class&amp;nbsp; &lt;font face="Courier New"&gt;LanguagesSerializer()&lt;/font&gt;. This was cool because it allowed me to accomplish what I wanted but it in turn forced me to now release two separate assemblies, &lt;font face="Courier New"&gt;CodeHtmler.dll&lt;/font&gt; and &lt;font face="Courier New"&gt;CodeHtmler.XmlSerializers.dll&lt;/font&gt;. Wouldn't it be nice if I could get away with just one assembly. It turns out that &lt;a href="http://msdn.microsoft.com/en-us/library/bk3w6240(vs.80).aspx"&gt;sgen&lt;/a&gt; has this /keep option that will tell it not to delete the temp code files used to build the new assembly. This was great because now I can just take the generated source code for the &lt;font face="Courier New"&gt;LanguagesSerializer&lt;/font&gt; class and build it as part of my &lt;font face="Courier New"&gt;CodeHtmler.dll&lt;/font&gt; assembly. Here is the command line I used to do this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;sgen CodeHtmler.dll /keep /force /type:CodeHtmler.Languages&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;There is a little bit of the chicken and egg problem here because I needed the &lt;font face="Courier New"&gt;CodeHtmler.dll&lt;/font&gt; to generate the serialization code and I needed serialization code to build &lt;font face="Courier New"&gt;CodeHtmler.dll&lt;/font&gt;. It really wasn't that big of an issue though because the serialization doesn't actually need to work to run &lt;a href="http://msdn.microsoft.com/en-us/library/bk3w6240(vs.80).aspx"&gt;sgen&lt;/a&gt; it just needs to be stubbed out so &lt;font face="Courier New"&gt;CodeHtmler.dll&lt;/font&gt; can be built. &lt;/p&gt;
&lt;p&gt;This approach works quite nicely. Now the only issue is that I have to remember to regenerate the serialization code whenever I change any of my serialized classes. Fortunately, I only have a small number of classes I serialize and their serialization interface doesn't change much so I think I can live with this approach.&lt;/p&gt;</description><pubDate>Mon, 14 Jan 2008 06:35:08 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/issues-with-the-xmlserializer-in-medium-trust-environments</guid><category>.NET</category><category>Code</category><category>CodeHTMLer</category><category>Tips and Tricks</category><category>Tools</category></item><item><title>Added CodeHTMLer project at codeplex</title><link>https://weblogs.asp.net:443/whaggard/added-codehtmler-project-at-codeplex</link><description>&lt;p&gt;In order to help better manage changes to &lt;a href="http://puzzleware.net/CodeHtmler"&gt;CodeHTMLer&lt;/a&gt; I finally added the project on &lt;a href="http://codeplex.com"&gt;codeplex&lt;/a&gt; at &lt;a href="http://codeplex.com/CodeHtmer"&gt;http://codeplex.com/CodeHtmer&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;I made a couple of small code updates after I put it up on &lt;a href="http://codeplex.com"&gt;codeplex&lt;/a&gt;:&lt;br&gt;- Added a new language property DivInlineFont to define the font to use when not using pre tags.&lt;br&gt;- Added a language definition for F# (thanks to &lt;a href="http://devhawk.net"&gt;Harry&lt;/a&gt; at &lt;a title="Blogging in F#" href="http://devhawk.net/2007/12/07/Blogging+F+Code.aspx"&gt;Blogging in F#&lt;/a&gt;)&lt;br&gt;- Fixed the CodeHTMLer library so it runs in a medium trust environment (needed this because I just moved web hosts and the new one runs in medium trust level, more about the details later).&lt;/p&gt; &lt;p&gt;Thus far &lt;a href="http://codeplex.com"&gt;codeplex&lt;/a&gt; seems pretty cool but I guess I will only be able to realize its full collaboration potential when I actually have more contributors than just myself.&lt;/p&gt;</description><pubDate>Mon, 14 Jan 2008 05:31:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/added-codehtmler-project-at-codeplex</guid><category>CodeHTMLer</category><category>News</category></item><item><title>Fun with C# functions</title><link>https://weblogs.asp.net:443/whaggard/fun-with-c-functions</link><description>&lt;p&gt;&lt;a href="http://diditwith.net/2007/08/01/ItsAllAboutMe.aspx"&gt;Dustin Campbell&lt;/a&gt; has an interesting series on C# functions on his &lt;a href="http://diditwith.net/default.aspx"&gt;Did it with .NET&lt;/a&gt; blog.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;a href="http://diditwith.net/ct.ashx?id=51510d4d-6f5d-4e29-95e8-ded8f23b3b7d&amp;amp;url=http%3a%2f%2fdiditwith.net%2f2007%2f02%2f08%2fFibonacciNumbersCachingAndClosures.aspx"&gt;Fibonacci Numbers, Caching and Closures&lt;/a&gt; &lt;li&gt;&lt;a href="http://diditwith.net/ct.ashx?id=51510d4d-6f5d-4e29-95e8-ded8f23b3b7d&amp;amp;url=http%3a%2f%2fdiditwith.net%2f2007%2f02%2f09%2fWhatsInAClosure.aspx"&gt;What's in a Closure?&lt;/a&gt; &lt;li&gt;&lt;a href="http://diditwith.net/ct.ashx?id=51510d4d-6f5d-4e29-95e8-ded8f23b3b7d&amp;amp;url=http%3a%2f%2fdiditwith.net%2f2007%2f02%2f12%2fUsingAutomaticMemoization.aspx"&gt;Using Automatic Memoization&lt;/a&gt; &lt;li&gt;&lt;a href="http://diditwith.net/ct.ashx?id=51510d4d-6f5d-4e29-95e8-ded8f23b3b7d&amp;amp;url=http%3a%2f%2fdiditwith.net%2f2007%2f06%2f21%2fAHigherCalling.aspx"&gt;A Higher Calling&lt;/a&gt; &lt;li&gt;&lt;a href="http://diditwith.net/ct.ashx?id=51510d4d-6f5d-4e29-95e8-ded8f23b3b7d&amp;amp;url=http%3a%2f%2fdiditwith.net%2f2007%2f08%2f15%2fTheArtOfCurrying.aspx"&gt;The Art of Currying&lt;/a&gt; &lt;li&gt;&lt;a href="http://diditwith.net/ct.ashx?id=51510d4d-6f5d-4e29-95e8-ded8f23b3b7d&amp;amp;url=http%3a%2f%2fdiditwith.net%2f2007%2f09%2f20%2fBuildingFunctionsFromFunctionsPart1PartialApplication.aspx"&gt;Building Functions from Functions, part 1: Partial Application&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://diditwith.net/2007/10/23/BuildingFunctionsFromFunctionsPart2FunctionComposition.aspx"&gt;Building Functions from Functions, part 2: Function Composition&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Some interesting stuff that ties together a number of C# 2.0 and 3.0 feature sets. Definitely worth a read. Thanks Dustin and keep them coming. &lt;/p&gt;</description><pubDate>Sun, 11 Nov 2007 21:26:10 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/fun-with-c-functions</guid><category>.NET</category><category>Code</category></item><item><title>Failure creating an Outlook application object on Vista</title><link>https://weblogs.asp.net:443/whaggard/failure-creating-an-outlook-application-object-on-vista</link><description>&lt;p&gt;While creating a Outlook application object from another process in C# like:&lt;/p&gt; &lt;blockquote&gt;&lt;pre&gt;outlook = &lt;span style="color: blue"&gt;new&lt;/span&gt; Microsoft.Office.Interop.Outlook.Application();&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;or powershell&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #2b91af"&gt;PS&lt;/span&gt;&amp;gt; &lt;span style="color: #35687d"&gt;$outlook&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;new-object&lt;/span&gt; -com Outlook.Application&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;or straight up COM via CoCreateInstance on Vista it's possible to receive the following error:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Error 0x80080005 (&lt;a href="http://blogs.msdn.com/adioltean/archive/2005/06/24/432519.aspx"&gt;CO_E_SERVER_EXEC_FAILURE&lt;/a&gt;) is sort of a generic COM error message that occurs for many reasons while calling CoCreateInstance. One reason someone could receive this error is because the client process and the server process (outlook.exe in this case) are running at different &lt;a href="http://msdn.microsoft.com/en-us/library/bb625964.aspx"&gt;integrity&lt;/a&gt; &lt;a href="http://blogs.technet.com/steriley/archive/2006/07/21/442870.aspx"&gt;levels&lt;/a&gt;. By default it doesn't appear that COM likes talking across two different processes that are running at different integrity levels. There &lt;a href="http://forums.microsoft.com/msdn/showpost.aspx?postid=942754&amp;amp;siteid=1&amp;amp;sb=0&amp;amp;d=1&amp;amp;at=7&amp;amp;ft=11&amp;amp;tf=0&amp;amp;pageid=0"&gt;supposedly&lt;/a&gt; is a way to implement the COM server in such a way to support it but currently the Outlook COM server doesn't support it.&lt;/p&gt;
&lt;p&gt;People who develop their applications on Vista using Visual Studio, which runs at integrity level high by default, will run into this issue often when Outlook is already running. By default Outlook runs at integrity level medium and if the client application is run from Visual Studio it will inherit the high integrity level and thus there will be an integrity level mismatch. &lt;/p&gt;
&lt;p&gt;To fix this one needs to make the integrity levels match so either start the client application outside Visual Studio at the normal medium integrity level or run Outlook at the high integrity level (i.e. as Administrator). However it is not recommended to run Outlook at integrity level high all the time. Another way to deal with this is to ensure Outlook is not already running so COM will start the process at the correct integrity level of the client process that created the application object. &lt;/p&gt;
&lt;p&gt;I don't know of any way to detect this exact situation programmatically but &lt;a href="http://www.microsoft.com/technet/sysinternals/utilities/processexplorer.mspx"&gt;process explorer&lt;/a&gt; works well for manually checking the integrity levels of processes.&lt;/p&gt;</description><pubDate>Mon, 05 Nov 2007 05:56:34 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/failure-creating-an-outlook-application-object-on-vista</guid><category>.NET</category><category>Code</category><category>Outlook</category></item><item><title>Why does my Outlook event seem to stop working?</title><link>https://weblogs.asp.net:443/whaggard/why-does-my-outlook-event-seem-to-stop-working</link><description>&lt;p&gt;Imagine&amp;nbsp;we have some code in an Outlook addin that looks similar to code below. Does anyone see anything wrong with it? It simply places a button on the menu bar and shows a message box when the button is clicked. The code works for sometime but then all of a sudden the button mysteriously stops working. What gives?&amp;nbsp;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; Office = Microsoft.Office.Core;
&lt;span style="color: blue"&gt;using&lt;/span&gt; Outlook = Microsoft.Office.Interop.Outlook;
...&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; SetupCommandBar(Outlook.Application application)
{
    Office.CommandBar menu = application.ActiveExplorer().CommandBars.ActiveMenuBar;

    Office.CommandBarButton button = menu.Controls.Add(Office.MsoControlType.msoControlButton,
        Type.Missing, Type.Missing, Type.Missing, &lt;span style="color: maroon"&gt;true&lt;/span&gt;) &lt;span style="color: blue"&gt;as&lt;/span&gt; Office.CommandBarButton;

    button.Caption = &lt;span style="color: maroon"&gt;"Click Me!"&lt;/span&gt;;
    button.Click += &lt;span style="color: blue"&gt;new&lt;/span&gt; Office._CommandBarButtonEvents_ClickEventHandler(button_Click);
}&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; button_Click(Microsoft.Office.Core.CommandBarButton Ctrl, &lt;span style="color: blue"&gt;ref&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; CancelDefault)
{
    System.Windows.Forms.MessageBox.Show(&lt;span style="color: maroon"&gt;"Clicked Button!"&lt;/span&gt;);
}&lt;/pre&gt;
&lt;p&gt;The button stops working due to the mystical powers of the .Net garbage collector. If we look closely we notice that the &lt;font face="Courier New"&gt;button&lt;/font&gt; object is locally scoped in the &lt;font face="Courier New"&gt;SetupCommandBar&lt;/font&gt; function, thus once we execute that function the &lt;font face="Courier New"&gt;button&lt;/font&gt; object is free to be cleaned up. However, until the &lt;font face="Courier New"&gt;button&lt;/font&gt; object is actually destroyed by the garbage collector the button click event will fire and the button will work. Due to the&amp;nbsp;non-deterministic nature of the garbage collector we have no idea how long the button will work. In my simple testing it seemed to work for a little while but if you want to speed up the process add a call go &lt;font face="Courier New"&gt;GC.Collect&lt;/font&gt; in the &lt;font face="Courier New"&gt;button_Click&lt;/font&gt; callback. &lt;/p&gt;
&lt;p&gt;The easiest fix for this problem is to change the scope of the &lt;font face="Courier New"&gt;button&lt;/font&gt; object to be a&amp;nbsp;member variable of enclosing class. By doing this we ensure that the &lt;font face="Courier New"&gt;button&lt;/font&gt; object stays alive and works until we are ready for it to stop working.&lt;/p&gt;</description><pubDate>Wed, 04 Jul 2007 06:53:32 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/why-does-my-outlook-event-seem-to-stop-working</guid><category>.NET</category><category>Code</category><category>Outlook</category></item><item><title>Powershell script to find strings and highlight them in the output</title><link>https://weblogs.asp.net:443/whaggard/powershell-script-to-find-strings-and-highlight-them-in-the-output</link><description>&lt;p&gt;After reading about &lt;a href="http://www.agileprogrammer.com/dotnetguy/"&gt;Brad&lt;/a&gt;'s &lt;a href="http://www.agileprogrammer.com/dotnetguy/archive/2007/03/22/22511.aspx"&gt;find&lt;/a&gt; script I starting thinking about how cool it would be if I could&amp;nbsp;highlight the search pattern in the output. So I&amp;nbsp;wrote my own custom Find-String script to highlight the results.&lt;/p&gt; &lt;h3&gt;Find-String.ps1&lt;/h3&gt; &lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: green"&gt;# Find-String.ps1&lt;/span&gt;
&lt;span style="color: green"&gt;#  Wrapper around dir | select-string which will highlight the pattern in the results&lt;/span&gt;
&lt;span style="color: blue"&gt;param&lt;/span&gt;	( [&lt;span style="color: blue"&gt;string&lt;/span&gt;] &lt;span style="color: #35687d"&gt;$pattern&lt;/span&gt; = &lt;span style="color: maroon"&gt;""&lt;/span&gt;
	, [&lt;span style="color: blue"&gt;string&lt;/span&gt;] &lt;span style="color: #35687d"&gt;$filter&lt;/span&gt; = &lt;span style="color: maroon"&gt;"*.*"&lt;/span&gt;
	, [&lt;span style="color: blue"&gt;switch&lt;/span&gt;] &lt;span style="color: #35687d"&gt;$recurse&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$false&lt;/span&gt;
	, [&lt;span style="color: blue"&gt;switch&lt;/span&gt;] &lt;span style="color: #35687d"&gt;$caseSensitive&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$false&lt;/span&gt;)

&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$pattern&lt;/span&gt; -eq &lt;span style="color: #35687d"&gt;$null&lt;/span&gt; -or &lt;span style="color: #35687d"&gt;$pattern&lt;/span&gt; -eq &lt;span style="color: maroon"&gt;""&lt;/span&gt;) { &lt;span style="color: #2b91af"&gt;Write-Error&lt;/span&gt; &lt;span style="color: maroon"&gt;"Please provide a search pattern!"&lt;/span&gt; ; &lt;span style="color: blue"&gt;return&lt;/span&gt; }

&lt;span style="color: #35687d"&gt;$regexPattern&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$pattern&lt;/span&gt;
&lt;span style="color: blue"&gt;if&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$caseSensitive&lt;/span&gt; -eq &lt;span style="color: #35687d"&gt;$false&lt;/span&gt;) { &lt;span style="color: #35687d"&gt;$regexPattern&lt;/span&gt; = &lt;span style="color: maroon"&gt;"(?i)$regexPattern"&lt;/span&gt; }
&lt;span style="color: #35687d"&gt;$regex&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;New-Object&lt;/span&gt; System.Text.RegularExpressions.Regex &lt;span style="color: #35687d"&gt;$regexPattern&lt;/span&gt;

&lt;span style="color: green"&gt;# Write the line with the pattern highlighted in red&lt;/span&gt;
&lt;span style="color: blue"&gt;function&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Write&lt;/span&gt;-HostAndHighlightPattern([&lt;span style="color: blue"&gt;string&lt;/span&gt;]&lt;span style="color: #35687d"&gt;$inputText&lt;/span&gt;)
{
	&lt;span style="color: #35687d"&gt;$index&lt;/span&gt; = &lt;span style="color: maroon"&gt;0&lt;/span&gt;
	&lt;span style="color: blue"&gt;while&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$index&lt;/span&gt; -lt &lt;span style="color: #35687d"&gt;$inputText&lt;/span&gt;.Length)
	{
		&lt;span style="color: #35687d"&gt;$match&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$regex&lt;/span&gt;.Match(&lt;span style="color: #35687d"&gt;$inputText&lt;/span&gt;, &lt;span style="color: #35687d"&gt;$index&lt;/span&gt;)
		&lt;span style="color: blue"&gt;if&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$match&lt;/span&gt;.Success -and &lt;span style="color: #35687d"&gt;$match&lt;/span&gt;.Length -gt &lt;span style="color: maroon"&gt;0&lt;/span&gt;)
		{
			&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: #35687d"&gt;$inputText&lt;/span&gt;.SubString(&lt;span style="color: #35687d"&gt;$index&lt;/span&gt;, &lt;span style="color: #35687d"&gt;$match&lt;/span&gt;.Index - &lt;span style="color: #35687d"&gt;$index&lt;/span&gt;) -nonewline
			&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: #35687d"&gt;$match&lt;/span&gt;.Value.ToString() -ForegroundColor Red -nonewline
			&lt;span style="color: #35687d"&gt;$index&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$match&lt;/span&gt;.Index + &lt;span style="color: #35687d"&gt;$match&lt;/span&gt;.Length
		}
		&lt;span style="color: blue"&gt;else&lt;/span&gt;
		{
			&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: #35687d"&gt;$inputText&lt;/span&gt;.SubString(&lt;span style="color: #35687d"&gt;$index&lt;/span&gt;) -nonewline
			&lt;span style="color: #35687d"&gt;$index&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$inputText&lt;/span&gt;.Length
		}
	}
}

&lt;span style="color: green"&gt;# Do the actual find in the files&lt;/span&gt;
&lt;span style="color: #2b91af"&gt;Get-ChildItem&lt;/span&gt; -recurse:&lt;span style="color: #35687d"&gt;$recurse&lt;/span&gt; -&lt;span style="color: blue"&gt;filter&lt;/span&gt;:&lt;span style="color: #35687d"&gt;$filter&lt;/span&gt; | 
	&lt;span style="color: #2b91af"&gt;Select-String&lt;/span&gt; -caseSensitive:&lt;span style="color: #35687d"&gt;$caseSensitive&lt;/span&gt; -pattern:&lt;span style="color: #35687d"&gt;$pattern&lt;/span&gt; |	
	&lt;span style="color: blue"&gt;foreach&lt;/span&gt; {
		&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt; &lt;span style="color: maroon"&gt;"$($_.FileName)($($_.LineNumber)): "&lt;/span&gt; -nonewline
		&lt;span style="color: #2b91af"&gt;Write&lt;/span&gt;-HostAndHighlightPattern &lt;span style="color: #35687d"&gt;$_&lt;/span&gt;.Line
		&lt;span style="color: #2b91af"&gt;Write-Host&lt;/span&gt;
	}
&lt;/pre&gt;
&lt;h3&gt;Sample Output&lt;/h3&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;PS&amp;gt; ./Find-String new-object&lt;br&gt;Find-String.ps1(13): $regex = &lt;font color="#ff0000"&gt;New-Object&lt;/font&gt; System.Text.RegularExpressions.Regex $regexPattern&lt;br&gt;Get-ApptsUsingEWS.ps1(55): $responseXml = [xml](&lt;font color="#ff0000"&gt;new-object&lt;/font&gt; System.IO.StreamReader $responseStream).ReadToEnd()&lt;br&gt;Get-ApptsUsingOOM.ps1(6): $outlook = &lt;font color="#ff0000"&gt;New-Object&lt;/font&gt; -ComObject Outlook.Application&lt;br&gt;getappts.ps1(51): $responseXml = [xml](&lt;font color="#ff0000"&gt;new-object&lt;/font&gt; System.IO.StreamReader $responseStream).ReadToEnd()&lt;br&gt;printAppts.ps1(6): $outlook = &lt;font color="#ff0000"&gt;New-Object&lt;/font&gt; -ComObject Outlook.Application&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For reference here are some other find scripts around the blogsphere: &lt;a href="http://www.agileprogrammer.com/dotnetguy/archive/2007/03/22/22511.aspx"&gt;Brad Wilson&lt;/a&gt;, &lt;a href="http://www.interact-sw.co.uk/iangblog/2006/06/03/pshfindstr"&gt;Ian Griffith&lt;/a&gt; and&amp;nbsp;&lt;a href="http://keithhill.spaces.live.com/blog/cns!5A8D2641E0963A97!407.entry"&gt;Keith Hill&lt;/a&gt;.&lt;/p&gt;</description><pubDate>Fri, 23 Mar 2007 06:11:04 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/powershell-script-to-find-strings-and-highlight-them-in-the-output</guid><category>.NET</category><category>Code</category><category>Powershell</category></item><item><title>Retrieving your Outlook appointments for a given date range</title><link>https://weblogs.asp.net:443/whaggard/retrieving-your-outlook-appointments-for-a-given-date-range</link><description>&lt;p&gt;Before we dive into the code sample lets take a quick look at what it means for an appointment to fall into a given date range.&lt;/p&gt; &lt;p&gt;&lt;img src="http://puzzleware.net/images/rangediagram.png"&gt;&lt;/p&gt; &lt;p&gt;When you compare an appointment&amp;nbsp;with a given date range (or any two time intervals)&amp;nbsp;there are the 6 possible outcomes displayed in the diagram above.&amp;nbsp;Usually as a first attempt people write a comparison that looks like:&lt;/p&gt;&lt;pre&gt;&lt;span style="color: maroon"&gt;[Start] &amp;gt;= RangeStart AND [End] &amp;lt;= RangeEnd&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;If you examine that comparison closely you will notice that it will only retrieve appointments of type 1. This maybe fine for most applications, like getting all appointments for a given week because there usually aren't any appointments spanning over the range&amp;nbsp;edges. However, if you want to be more precise and include any appointments that overlap with a given date range (i.e. type 1, 2, 3, 4) you can use the following comparison:&lt;/p&gt;&lt;pre&gt;&lt;span style="color: maroon"&gt;[End] &amp;gt;=&amp;nbsp;RangeStart AND [Start] &amp;lt;=&amp;nbsp;RangeEnd&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;This type of restriction will help when you have smaller date/time ranges such as a few hours or a day. In general, unless you specifically only want type 1 appointments, I would recommend using this restriction which finds any appointments that overlap with the given date/time range.&lt;/p&gt;
&lt;p&gt;Since &lt;a href="http://blogs.msdn.com/waltwa/"&gt;Walter&lt;/a&gt; has already provided a &lt;a href="http://blogs.msdn.com/waltwa/archive/2007/03/14/finding-appointments-within-a-specific-timeframe.aspx"&gt;VBA, WebDAV, and CDO&lt;/a&gt; code sample on how to find&amp;nbsp;appointments within a specific time frame, I figured I would provide some Powershell code samples.&lt;/p&gt;
&lt;h3&gt;Powershell script to&amp;nbsp;retrieve appointments using the Outlook Object Model&amp;nbsp;for a given date range.&lt;/h3&gt;
&lt;p&gt;Keep in mind in order to get all the appointments, including any instances of recurring appointments, you need to get the&amp;nbsp;items collection on the calendar&amp;nbsp;folder&amp;nbsp;and then&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb220097.aspx"&gt;Sort&lt;/a&gt; by the "[Start]" property and set &lt;a href="http://msdn.microsoft.com/en-us/library/bb220097.aspx"&gt;IncludeRecurrences&lt;/a&gt; to true. Once you have done this&amp;nbsp;the Count property on the items collection is bogus because there could potentially be an infinite number of recurring appointments. So to traverse this collection you need to use the enumerator (i.e. foreach) or use the &lt;a href="http://msdn.microsoft.com/en-us/library/bb220350.aspx"&gt;Find&lt;/a&gt;/&lt;a href="http://msdn.microsoft.com/en-us/library/bb219895.aspx"&gt;FindNext&lt;/a&gt; methods on the collection.&lt;/p&gt;&lt;pre&gt;&lt;span style="color: green"&gt;# Get-ApptsUsingOOM.ps1&lt;/span&gt;
&lt;span style="color: green"&gt;#    Powershell script to retrieve all appointments for a given date range using the Outlook Object Model&lt;/span&gt;
param ( [DateTime] &lt;span style="color: #35687d"&gt;$rangeStart&lt;/span&gt; = [DateTime]::Now
      , [DateTime] &lt;span style="color: #35687d"&gt;$rangeEnd&lt;/span&gt;   = [DateTime]::Now.AddDays(&lt;span style="color: maroon"&gt;7&lt;/span&gt;))

&lt;span style="color: #35687d"&gt;$outlook&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;New-Object&lt;/span&gt; -ComObject Outlook.Application

&lt;span style="color: green"&gt;# Ensure we are logged into a session&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$session&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$outlook&lt;/span&gt;.Session
&lt;span style="color: #35687d"&gt;$session&lt;/span&gt;.Logon()

&lt;span style="color: #35687d"&gt;$olFolderCalendar&lt;/span&gt; = &lt;span style="color: maroon"&gt;9&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$apptItems&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$session&lt;/span&gt;.GetDefaultFolder(&lt;span style="color: #35687d"&gt;$olFolderCalendar&lt;/span&gt;).Items
&lt;span style="color: #35687d"&gt;&lt;span style="color: #35687d"&gt;$apptItems&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;Sort&lt;/span&gt;(&lt;span style="color: maroon"&gt;"[Start]"&lt;/span&gt;)&lt;br&gt;&lt;/span&gt;&lt;span style="color: #35687d"&gt;$apptItems&lt;/span&gt;.IncludeRecurrences = &lt;span style="color: #35687d"&gt;$true&lt;/span&gt;

&lt;span style="color: #35687d"&gt;$restriction&lt;/span&gt; = &lt;span style="color: maroon"&gt;"[End] &amp;gt;= '{0}' AND [Start] &amp;lt;= '{1}'"&lt;/span&gt; -f &lt;span style="color: #35687d"&gt;$rangeStart&lt;/span&gt;.ToString(&lt;span style="color: maroon"&gt;"g"&lt;/span&gt;), &lt;span style="color: #35687d"&gt;$rangeEnd&lt;/span&gt;.ToString(&lt;span style="color: maroon"&gt;"g"&lt;/span&gt;)

&lt;span style="color: blue"&gt;foreach&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$appt&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: #35687d"&gt;$apptItems&lt;/span&gt;.Restrict(&lt;span style="color: #35687d"&gt;$restriction&lt;/span&gt;))
{
    &lt;span style="color: maroon"&gt;"{0:MM/dd hh:mm tt} - {1:MM/dd hh:mm tt} : {2}"&lt;/span&gt; -f [DateTime]&lt;span style="color: #35687d"&gt;$appt&lt;/span&gt;.Start, [DateTime]&lt;span style="color: #35687d"&gt;$appt&lt;/span&gt;.End, &lt;span style="color: #35687d"&gt;$appt&lt;/span&gt;.Subject
}

&lt;span style="color: #35687d"&gt;$outlook&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$session&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$null&lt;/span&gt;;&lt;/pre&gt;
&lt;h3&gt;Powershell script to retrieve appointments using Exchange Web Services for a given date range&lt;/h3&gt;
&lt;p&gt;For simplicity I built the soap message manually and submitted the request, but you could easily generate the web service proxy classes using &lt;a href="http://msdn.microsoft.com/en-us/library/7h3ystb6(VS.80).aspx"&gt;wsdl.exe&lt;/a&gt; like I did in &lt;a href="http://weblogs.asp.net/whaggard/archive/2007/01/30/how-do-i-access-my-outlook-contacts-from-my-web-application.aspx"&gt;another example&lt;/a&gt;&amp;nbsp;if you don't wish to build the soap message yourself.&lt;/p&gt;&lt;pre&gt;&lt;span style="color: green"&gt;# GetApptsUsingEWS.ps1&lt;/span&gt;
&lt;span style="color: green"&gt;#    Powershell script to retrieve all appointments for a given date range using Exchange Web Services&lt;/span&gt;
param ( [DateTime] &lt;span style="color: #35687d"&gt;$rangeStart&lt;/span&gt; = [DateTime]::Now
      , [DateTime] &lt;span style="color: #35687d"&gt;$rangeEnd&lt;/span&gt;   = [DateTime]::Now.AddDays(&lt;span style="color: maroon"&gt;7&lt;/span&gt;)
      , [System.Net.NetworkCredential] &lt;span style="color: #35687d"&gt;$credentials&lt;/span&gt; = (&lt;span style="color: #2b91af"&gt;Get-Credential&lt;/span&gt;).GetNetworkCredential())

&lt;span style="color: green"&gt;# Remember to set your exchange server address&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$exchangeServerAddress&lt;/span&gt; = &lt;span style="color: maroon"&gt;"http&amp;lt;s&amp;gt;://&amp;lt;ExchangeServer&amp;gt;/EWS/Exchange.asmx"&lt;/span&gt;

&lt;span style="color: green"&gt;# Soap request derived from &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa564515.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa564515.aspx&lt;/a&gt;
&lt;span style="color: #35687d"&gt;$soapRequest&lt;/span&gt; = @'
&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: maroon"&gt;xml&lt;/span&gt; &lt;span style="color: red"&gt;version&lt;/span&gt;="&lt;span style="color: blue"&gt;1.0&lt;/span&gt;" &lt;span style="color: red"&gt;encoding&lt;/span&gt;="&lt;span style="color: blue"&gt;utf-8&lt;/span&gt;"&lt;span style="color: blue"&gt;?&amp;gt;&lt;/span&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;soap:Envelope&lt;/span&gt; &lt;span style="color: red"&gt;xmlns:xsi&lt;/span&gt;="&lt;span style="color: blue"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/span&gt;"
               &lt;span style="color: red"&gt;xmlns:xsd&lt;/span&gt;="&lt;span style="color: blue"&gt;http://www.w3.org/2001/XMLSchema&lt;/span&gt;"
               &lt;span style="color: red"&gt;xmlns:soap&lt;/span&gt;="&lt;span style="color: blue"&gt;http://schemas.xmlsoap.org/soap/envelope/&lt;/span&gt;"
               &lt;span style="color: red"&gt;xmlns:t&lt;/span&gt;="&lt;span style="color: blue"&gt;http://schemas.microsoft.com/exchange/services/2006/types&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;soap:Body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;FindItem&lt;/span&gt; &lt;span style="color: red"&gt;Traversal&lt;/span&gt;="&lt;span style="color: blue"&gt;Shallow&lt;/span&gt;" &lt;span style="color: red"&gt;xmlns&lt;/span&gt;="&lt;span style="color: blue"&gt;http://schemas.microsoft.com/exchange/services/2006/messages&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
      &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;ItemShape&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;t:BaseShape&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;IdOnly&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;t:BaseShape&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;t:AdditionalProperties&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
          &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;t:FieldURI&lt;/span&gt; &lt;span style="color: red"&gt;FieldURI&lt;/span&gt;="&lt;span style="color: blue"&gt;calendar:Start&lt;/span&gt;"/&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
          &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;t:FieldURI&lt;/span&gt; &lt;span style="color: red"&gt;FieldURI&lt;/span&gt;="&lt;span style="color: blue"&gt;calendar:End&lt;/span&gt;"/&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
          &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;t:FieldURI&lt;/span&gt; &lt;span style="color: red"&gt;FieldURI&lt;/span&gt;="&lt;span style="color: blue"&gt;item:Subject&lt;/span&gt;"/&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;t:AdditionalProperties&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
      &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;ItemShape&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
      &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;CalendarView&lt;/span&gt; &lt;span style="color: red"&gt;MaxEntriesReturned&lt;/span&gt;="&lt;span style="color: blue"&gt;100&lt;/span&gt;" &lt;span style="color: red"&gt;StartDate&lt;/span&gt;="&lt;span style="color: blue"&gt;{0}&lt;/span&gt;" &lt;span style="color: red"&gt;EndDate&lt;/span&gt;="&lt;span style="color: blue"&gt;{1}&lt;/span&gt;"/&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
      &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;ParentFolderIds&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;t:DistinguishedFolderId&lt;/span&gt; &lt;span style="color: red"&gt;Id&lt;/span&gt;="&lt;span style="color: blue"&gt;calendar&lt;/span&gt;"/&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
      &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;ParentFolderIds&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;FindItem&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;soap:Body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;soap:Envelope&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
'@

&lt;span style="color: green"&gt;# Put the range start and end date in the correct format&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$soapRequest&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$soapRequest&lt;/span&gt; -f &lt;span style="color: #35687d"&gt;$rangeStart&lt;/span&gt;.ToString(&lt;span style="color: maroon"&gt;"yyyy-MM-ddTHH:mm:sszzz"&lt;/span&gt;), &lt;span style="color: #35687d"&gt;$rangeEnd&lt;/span&gt;.ToString(&lt;span style="color: maroon"&gt;"yyyy-MM-ddTHH:mm:sszzz"&lt;/span&gt;)

&lt;span style="color: green"&gt;# Create the request &lt;/span&gt;
&lt;span style="color: #35687d"&gt;$webRequest&lt;/span&gt; = [System.Net.WebRequest]::Create(&lt;span style="color: #35687d"&gt;$exchangeServerAddress&lt;/span&gt;)
&lt;span style="color: #35687d"&gt;$webRequest&lt;/span&gt;.ContentType = &lt;span style="color: maroon"&gt;"text/xml"&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$webRequest&lt;/span&gt;.Headers.Add(&lt;span style="color: maroon"&gt;"Translate"&lt;/span&gt;, &lt;span style="color: maroon"&gt;"F"&lt;/span&gt;)
&lt;span style="color: #35687d"&gt;$webRequest&lt;/span&gt;.Method = &lt;span style="color: maroon"&gt;"Post"&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$webRequest&lt;/span&gt;.Credentials = &lt;span style="color: #35687d"&gt;$credentials&lt;/span&gt;

&lt;span style="color: green"&gt;# Setup the soap request to send to the server&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$content&lt;/span&gt; = [System.Text.Encoding]::UTF8.GetBytes(&lt;span style="color: #35687d"&gt;$soapRequest&lt;/span&gt;)
&lt;span style="color: #35687d"&gt;$webRequest&lt;/span&gt;.ContentLength = &lt;span style="color: #35687d"&gt;$content&lt;/span&gt;.Length
&lt;span style="color: #35687d"&gt;$requestStream&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$webRequest&lt;/span&gt;.GetRequestStream()
&lt;span style="color: #35687d"&gt;$requestStream&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;Write&lt;/span&gt;(&lt;span style="color: #35687d"&gt;$content&lt;/span&gt;, &lt;span style="color: maroon"&gt;0&lt;/span&gt;, &lt;span style="color: #35687d"&gt;$content&lt;/span&gt;.Length)
&lt;span style="color: #35687d"&gt;$requestStream&lt;/span&gt;.Close()

&lt;span style="color: green"&gt;# Get the xml response from the server&lt;/span&gt;
&lt;span style="color: #35687d"&gt;$webResponse&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$webRequest&lt;/span&gt;.GetResponse()
&lt;span style="color: #35687d"&gt;$responseStream&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$webResponse&lt;/span&gt;.GetResponseStream()
&lt;span style="color: #35687d"&gt;$responseXml&lt;/span&gt; = [xml](&lt;span style="color: #2b91af"&gt;new-object&lt;/span&gt; System.IO.StreamReader &lt;span style="color: #35687d"&gt;$responseStream&lt;/span&gt;).ReadToEnd()
&lt;span style="color: #35687d"&gt;$responseStream&lt;/span&gt;.Close()
&lt;span style="color: #35687d"&gt;$webResponse&lt;/span&gt;.Close()

&lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$appt&lt;/span&gt; &lt;span style="color: blue"&gt;in&lt;/span&gt; &lt;span style="color: #35687d"&gt;$responseXml&lt;/span&gt;.GetElementsByTagName(&lt;span style="color: maroon"&gt;"t:CalendarItem"&lt;/span&gt;))
{
    &lt;span style="color: maroon"&gt;"{0:MM/dd hh:mm tt} - {1:MM/dd hh:mm tt} : {2}"&lt;/span&gt; -f [DateTime]&lt;span style="color: #35687d"&gt;$appt&lt;/span&gt;.Start, [DateTime]&lt;span style="color: #35687d"&gt;$appt&lt;/span&gt;.End, &lt;span style="color: #35687d"&gt;$appt&lt;/span&gt;.Subject
}&lt;/pre&gt;</description><pubDate>Wed, 21 Mar 2007 06:43:28 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/retrieving-your-outlook-appointments-for-a-given-date-range</guid><category>.NET</category><category>Code</category><category>Outlook</category><category>Powershell</category></item><item><title>Reflector 5 Released</title><link>https://weblogs.asp.net:443/whaggard/reflector-5-released</link><description>&lt;p&gt;&lt;a href="http://www.aisto.com/roeder/"&gt;Lutz&lt;/a&gt; released&amp;nbsp;&lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector for .NET&lt;/a&gt;&amp;nbsp;5.0 &lt;/p&gt; &lt;p&gt;If you do any .NET development and you don't&amp;nbsp;use&amp;nbsp;&lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector for .NET&lt;/a&gt;&amp;nbsp;then you are missing out. &lt;a href="http://www.hanselman.com/"&gt;Scott&lt;/a&gt; posted a brief &lt;a href="http://www.hanselman.com/blog/Reflector5ReleasedWorldDominationAssured.aspx"&gt;review&lt;/a&gt; of the new version. I think I'm most excited about the&amp;nbsp;new analyze feature, it should come in handy.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector for .NET&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.codeplex.com/reflectoraddins"&gt;Reflector for .NET Add-Ins&lt;/a&gt;&lt;/p&gt;</description><pubDate>Wed, 21 Feb 2007 05:28:49 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/reflector-5-released</guid><category>.NET</category><category>News</category><category>Tools</category></item><item><title>Image File Execution Options</title><link>https://weblogs.asp.net:443/whaggard/image-file-execution-options</link><description>&lt;p&gt;Every now and than while debugging I need to either determine when a dll/module is loaded or need to attach a debugger to a process at startup that is started outside a debugger. I know there are settings that exist to do this but I always seem to forget exactly what they are. So for future reference here the registry entries.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Force a break while debugging when a dll/module is loaded&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\&amp;lt;modulename.dll&amp;gt;]&lt;br&gt;"BreakOnDllLoad"=dword:00000001&lt;br&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Force&amp;nbsp;a process to start&amp;nbsp;under the Visual Studio Debugger&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\&amp;lt;processname.exe&amp;gt;]&lt;br&gt;"Debugger"="vsjitdebugger.exe" &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Useful links:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/junfeng/"&gt;Junfeng&lt;/a&gt;&amp;nbsp;- &lt;a href="http://blogs.msdn.com/junfeng/archive/2004/04/28/121871.aspx"&gt;Image File Execution Options&lt;/a&gt;&lt;br&gt;&lt;a href="http://blogs.msdn.com/greggm/default.aspx"&gt;Greggm&lt;/a&gt;&amp;nbsp;- &lt;a href="http://blogs.msdn.com/greggm/archive/2004/07/08/177418.aspx"&gt;Breaking when a module loads&lt;/a&gt;&lt;br&gt;&lt;a href="http://blogs.msdn.com/greggm/default.aspx"&gt;Greggm&lt;/a&gt; - &lt;a href="http://blogs.msdn.com/greggm/archive/2005/02/21/377663.aspx"&gt;Inside 'Image File Execution Options' debugging&lt;/a&gt;&lt;br&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/"&gt;Oldnewthing&lt;/a&gt; - &lt;a href="http://blogs.msdn.com/oldnewthing/archive/2005/12/19/505449.aspx"&gt;Beware the Image File Execution Options key&lt;/a&gt;&lt;/p&gt;</description><pubDate>Fri, 09 Feb 2007 03:28:04 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/image-file-execution-options</guid><category>Tips and Tricks</category><category>Windows</category></item><item><title>Powershell version of cmd set</title><link>https://weblogs.asp.net:443/whaggard/powershell-version-of-cmd-set</link><description>&lt;p&gt;If you are like me and are just so used to typing &lt;strong&gt;set&lt;/strong&gt; to&amp;nbsp;list and set&amp;nbsp;environment variables then you might find this script useful. &lt;/p&gt;&lt;pre&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;test-path&lt;/span&gt; alias:set) { &lt;span style="color: #2b91af"&gt;remove-item&lt;/span&gt; alias:set &amp;gt; &lt;span style="color: #35687d"&gt;$null&lt;/span&gt; }
&lt;span style="color: blue"&gt;function&lt;/span&gt; set
{
	[string]&lt;span style="color: #35687d"&gt;$var&lt;/span&gt; = &lt;span style="color: #35687d"&gt;$args&lt;/span&gt;
	&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$var&lt;/span&gt; -eq &lt;span style="color: maroon"&gt;""&lt;/span&gt;)
	{
		&lt;span style="color: #2b91af"&gt;get-childitem&lt;/span&gt; env: | &lt;span style="color: #2b91af"&gt;sort-object&lt;/span&gt; name
	}
	&lt;span style="color: blue"&gt;else&lt;/span&gt;
	{
		&lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #35687d"&gt;$var&lt;/span&gt; -match &lt;span style="color: maroon"&gt;"^(\S*?)\s*=\s*(.*)$"&lt;/span&gt;)
		{
			&lt;span style="color: #2b91af"&gt;set-item&lt;/span&gt; -force -path &lt;span style="color: maroon"&gt;"env:$($matches[1])"&lt;/span&gt; -value &lt;span style="color: #35687d"&gt;$matches&lt;/span&gt;[&lt;span style="color: maroon"&gt;2&lt;/span&gt;];		
		}
		&lt;span style="color: blue"&gt;else&lt;/span&gt;
		{
			&lt;span style="color: #2b91af"&gt;write-error&lt;/span&gt; &lt;span style="color: maroon"&gt;"ERROR Usage: VAR=VALUE"&lt;/span&gt;
		}
	}	
}&lt;/pre&gt;
&lt;p&gt;Just add this script to your &lt;a href="http://blogs.msdn.com/powershell/"&gt;Powershell&lt;/a&gt; profile and you will be all set :)&lt;/p&gt;
&lt;p&gt;PS: If anyone is interested I updated the &lt;a href="http://blogs.msdn.com/powershell/"&gt;Powershell&lt;/a&gt; Language definitions for &lt;a href="http://puzzleware.net/codehtmler"&gt;CodeHTMLer&lt;/a&gt;, it now highlights more of the built-in stuff such as cmdlets and variables.&lt;/p&gt;</description><pubDate>Thu, 08 Feb 2007 20:24:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/whaggard/powershell-version-of-cmd-set</guid><category>Code</category><category>CodeHTMLer</category><category>Powershell</category><category>Tips and Tricks</category></item></channel></rss>