&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Articles from May 2013 on PowerShell.org - Welcome Automaters!</title><link>https://powershell.org/articles/2013/05/</link><description>Recent content in Articles from May 2013 on PowerShell.org - Welcome Automaters!</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://powershell.org/articles/2013/05/index.xml" rel="self" type="application/rss+xml"/><item><title>Meet the Scripting Games Judges</title><link>https://powershell.org/articles/2013-05-31-meet-the-scripting-games-judges/</link><guid>https://powershell.org/articles/2013-05-31-meet-the-scripting-games-judges/</guid><pubDate>Fri, 31 May 2013 20:42:17 +0000</pubDate><description>&lt;p&gt;I can honestly say that the interactions that I&amp;quot;™ve had with the PowerShell community over the past five years have been some of the most fulfilling. There is something to watching someone learn to script. Some plateau artificially mainly because they don&amp;quot;™t want to leave the GUI. Often they&amp;quot;™re forced into learning PowerShell and stubbornly go into trying to learn as little as possible. If you competed this year you do not fall into that category. You fall into the category that I love working with Talented Specialist that we watch graduate from good to great. I&amp;quot;™m happy to invite this year&amp;quot;™s class into &amp;ldquo;the club&amp;rdquo;.&lt;br&gt;
For everyone else I have an invitation. If you would like to know what makes a good script great and will be in New Orleans next week for TechEd 2012 NA, then please join the judges of the Scripting Games as we do a public Code review. Simply put we&amp;quot;™ll take a script and as a group discuss what makes it good and bad. We&amp;quot;™re calling it best practices for the real word, but you&amp;quot;™ll see it listed in the directory under &lt;a href="http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/BOF-ITP23#fbid=LcGTktzJqbc" title="BOF-ITP23"&gt;BOF-ITP23&lt;/a&gt;.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I can honestly say that the interactions that I"™ve had with the PowerShell community over the past five years have been some of the most fulfilling. There is something to watching someone learn to script. Some plateau artificially mainly because they don"™t want to leave the GUI. Often they"™re forced into learning PowerShell and stubbornly go into trying to learn as little as possible. If you competed this year you do not fall into that category. You fall into the category that I love working with Talented Specialist that we watch graduate from good to great. I"™m happy to invite this year"™s class into &ldquo;the club&rdquo;.<br>
For everyone else I have an invitation. If you would like to know what makes a good script great and will be in New Orleans next week for TechEd 2012 NA, then please join the judges of the Scripting Games as we do a public Code review. Simply put we"™ll take a script and as a group discuss what makes it good and bad. We"™re calling it best practices for the real word, but you"™ll see it listed in the directory under<a href="http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/BOF-ITP23#fbid=LcGTktzJqbc" title="BOF-ITP23">BOF-ITP23</a>.</p>
]]></content:encoded></item><item><title>Scripting Games Week 5</title><link>https://powershell.org/articles/2013-05-31-scripting-games-week-5/</link><guid>https://powershell.org/articles/2013-05-31-scripting-games-week-5/</guid><pubDate>Fri, 31 May 2013 15:02:17 +0000</pubDate><description>&lt;p&gt;I loved this week&amp;quot;™s challenge as it had the right wiggle room to bring out the best in our participants.  Of course, this is also the point in the games when we start to get everyone&amp;quot;™s &amp;ldquo;A&amp;rdquo; game.  At this point even our new competitors are all warmed up and in the zone, and let me tell you the entries this week show it!   I want to start with the beginners as I actually ran almost every entry this week.  Honestly everyone fell into one of three buckets Select-string, Import-CSV or ,Foreach.  Let me explain there where three primary means to solve this problem.  Use Select-String and some basic text parsing to get the ip addresses, and then using Select-Object to filter.  Converting the logs to objects with Import-CSV and using Where-Object to filter.  Or using Foreach and a combination of if and where.&lt;br&gt;
They are all three correct, so how does one judge one from another?  As this is a competition I used speed as the determining gauge.  For a long time I was convinced that the following was about perfect.  Quick simple and accurate.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I loved this week"™s challenge as it had the right wiggle room to bring out the best in our participants.  Of course, this is also the point in the games when we start to get everyone"™s &ldquo;A&rdquo; game.  At this point even our new competitors are all warmed up and in the zone, and let me tell you the entries this week show it!   I want to start with the beginners as I actually ran almost every entry this week.  Honestly everyone fell into one of three buckets Select-string, Import-CSV or ,Foreach.  Let me explain there where three primary means to solve this problem.  Use Select-String and some basic text parsing to get the ip addresses, and then using Select-Object to filter.  Converting the logs to objects with Import-CSV and using Where-Object to filter.  Or using Foreach and a combination of if and where.<br>
They are all three correct, so how does one judge one from another?  As this is a competition I used speed as the determining gauge.  For a long time I was convinced that the following was about perfect.  Quick simple and accurate.</p><p><code>Select-String -Path C:\Reporting\LogFiles\*\*.log -Pattern "(\b\d{1,3}\.){3}.\d{1,3}\b" -AllMatches | Select-Object -Unique @{Label="IP";Expression={$_.matches[1]}}</code>I was particularly drawn to this approach because it only used two cmdlets if that"™s not PowerShell I don"™t know what is. At first I was convinced converting the logs to objects was a waste.  Let me explain.  Over the course of this past month you"™ve heard us rant and rave about objects, and how PowerShell is not text, but rich .Net objects.  For the most part that is an iron law, but it"™s a law with an exception.  There is one place where text is just text, log files!  That"™s why I loved this event.  This is the exception where all the old tricks still apply and where we found out which of you really know your regular expressions.  However in this one instant since we had a well formed log converting to a CSV was actually faster.   I wasn"™t expecting that, but consider my gold standard example takes about 10 Seconds on my PC.   The Following finishes in 3!</p><p>`$LogFilePath = &lsquo;C:\Reporting\LogFiles&rsquo;
$header = &lsquo;date&rsquo;,&rsquo;time&rsquo;,&rsquo;s-ip&rsquo;,&lsquo;cs-method&rsquo;,&lsquo;cs-uri-stem&rsquo;,&lsquo;cs-uri-query&rsquo;,&rsquo;s-port&rsquo;,&lsquo;cs-username&rsquo;,&lsquo;c-ip&rsquo;,&lsquo;cs(User-Agent)&rsquo;,&lsquo;sc-status&rsquo;,&lsquo;sc-substatus&rsquo;,&lsquo;sc-win32-status&rsquo;,&rsquo;time-taken&rsquo;
Import-Csv -Path $(Get-ChildItem -Path $LogFilePath -File -Recurse).FullName -Header $header -Delimiter &rsquo; &rsquo; |</p><h1 id="if-the-contents-of-c-ip-can-be-converted-to-an-ip-address-then-it-is-a-valid-ip" class="ps-heading">if the contents of &lsquo;c-ip&rsquo; can be converted to an IP address then it is a valid IP<a class="ps-heading-anchor" href="#if-the-contents-of-c-ip-can-be-converted-to-an-ip-address-then-it-is-a-valid-ip" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><p>Select-Object @{n=&lsquo;ClientIP&rsquo;;e={if ([IPAddress]$<em>.&lsquo;c-ip&rsquo;){ $</em>.&lsquo;c-ip&rsquo; }}} |
Sort-Object -Property &lsquo;ClientIP&rsquo; -Unique
`Now I"™m not crazy about that entry it"™s hard to follow, and will always return a blank string, but if you really look what makes it work is the author is offloading the IP filtering to the [IPAddress] type accelerator.  That is brilliant, and is x5 faster than a regular expression, which really adds up when you"™re performing over 6k comparisons.   I know the general consensus is to leave the .Net stuff alone, but I have no religion when it comes to this stuff. If it"™s better it"™s better and in this instance it was better.<br>
But that"™s not the end of the story. While sorting through the entries I found the following solution.</p><p><code>Get-ChildItem -File C:\Reporting\LogFiles -Recurse | Get-Content | # Selecting "GET /" gives us only the lines we want from the files. Select-String -Pattern "GET /" | # Split the remaining lines into an array and write element 8, the IP, to a file. ForEach-Object {$_.Line.Split("")[8] } | Select-Object -Unique @{Name="Source Address"; Expression={$_}}</code>Now that"™s an old school PowerShell solution if I"™ve ever seen one, and you know what it"™s fast as hell!  There"™s no validation of any kind. It will only work with provided source files, and it"™s absolutely perfect!  You see the goal is to get the job done.  We don"™t always have to author a tool that can be used by the world.  There is nothing wrong with leveraging your brain and cheating a little!<br>
As for the advanced entries I think they"™ve been adequately covered by my fellow judges.  In general my feedback would be to start a slow clap for the group.  There not perfect, but as a group you"™ve learned from the feedback over this past month and man does it show! Heading into the final stretch I encourage you all to treat this last entry as your victory lap as you"™ve all already one.<br>
~Glenn</p>
]]></content:encoded></item><item><title>Free PowerShell Workshop Video from TechMentor and Me</title><link>https://powershell.org/articles/2013-05-31-free-powershell-workshop-video-from-techmentor-and-me/</link><guid>https://powershell.org/articles/2013-05-31-free-powershell-workshop-video-from-techmentor-and-me/</guid><pubDate>Fri, 31 May 2013 12:16:42 +0000</pubDate><description>&lt;p&gt;At the last &lt;a href="http://techmentorevents.com"&gt;TechMentor&lt;/a&gt; (in Orlando), I did a Windows PowerShell pre-conference workshop. The conference was kind enough to let me record it - I basically just used Camtasia, so this isn&amp;rsquo;t a professional video by any stretch, but it gives you an idea of what a TechMentor conference is like. Obviously, my focus was on the folks in the room, but you can see all of the demos and hear me pretty clearly. &lt;a href="http://techmentorevents.com/forms/don-jones-video.aspx"&gt;You can view the video for free&lt;/a&gt;, although note that registration is required.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>At the last<a href="http://techmentorevents.com">TechMentor</a> (in Orlando), I did a Windows PowerShell pre-conference workshop. The conference was kind enough to let me record it - I basically just used Camtasia, so this isn&rsquo;t a professional video by any stretch, but it gives you an idea of what a TechMentor conference is like. Obviously, my focus was on the folks in the room, but you can see all of the demos and hear me pretty clearly.<a href="http://techmentorevents.com/forms/don-jones-video.aspx">You can view the video for free</a>, although note that registration is required.</p>
]]></content:encoded></item><item><title>Tobias' Event 5 Notes</title><link>https://powershell.org/articles/2013-05-31-tobias-event-5-notes/</link><guid>https://powershell.org/articles/2013-05-31-tobias-event-5-notes/</guid><pubDate>Fri, 31 May 2013 12:12:45 +0000</pubDate><description>&lt;p&gt;Find &amp;rsquo;em at &lt;a href="http://www.powertheshell.com/scripting-games-task-5-commentary/"&gt;http://www.powertheshell.com/scripting-games-task-5-commentary/&lt;/a&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Find &rsquo;em at<a href="http://www.powertheshell.com/scripting-games-task-5-commentary/">http://www.powertheshell.com/scripting-games-task-5-commentary/</a></p>
]]></content:encoded></item><item><title>Notes on Event 5</title><link>https://powershell.org/articles/2013-05-30-notes-on-event-5/</link><guid>https://powershell.org/articles/2013-05-30-notes-on-event-5/</guid><pubDate>Thu, 30 May 2013 13:54:17 +0000</pubDate><description>&lt;p&gt;Into the home stretch and the entries just keep getting better! The only advice I&amp;rsquo;d like to offer this time is to be careful to read the instructions carefully. They included the specific folder where the files were located and I noticed several misinterpretations in the scripts. Some included a mandatory Path parameter and others had a default Path that was not the specified folder. Including an optional Path with the correct default would certainly be acceptable, but not those variations.&lt;br&gt;
The instructions also included some ambiguity about what the log file actually contains. Was the client IP address in the first column (as specified in the instructions) or in a different column (as presented in the example logs)? There were a number of entries that just searched the logs for IP addresses and returned all of them. This approach would not be able to distinguished between the client and server addresses, which would give a wrong answer. Another approach searched for the &amp;ldquo;c-ip&amp;rdquo; column, but this would only work if the log files were as in the samples. Another method, select the second IP address in a line would also only work on the sample log style. There weren&amp;rsquo;t many entries that supported both file types, but one of them did it in a very concise manner, checking the first and ninth columns for an IP address and selecting the correct one.&lt;br&gt;
Most of the entries used &lt;em&gt;Sort-Object -Unique&lt;/em&gt; or &lt;em&gt;Select-Object -Unique&lt;/em&gt; to eliminate duplicates, which was the first approach that I thought of. There were several entries, however, that used alternate methods that I thought were quite clever applications of PowerShell technology: hash tables with the IP address as the key, and &lt;em&gt;Group-Object&lt;/em&gt; on the IP address. Both options provided a fairly simple way to also report the instance count for each address.&lt;br&gt;
Returning an instance count sounds like an interesting option, but after thinking about it some more, I&amp;rsquo;m not so sure. Counts of the number of sessions and the hits per session would be much more interesting than the raw hits count. But that&amp;rsquo;s way, way beyond the scope of this event.&lt;br&gt;
Anyway, just one more event to go. I&amp;rsquo;m expecting a spectacular finish!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Into the home stretch and the entries just keep getting better! The only advice I&rsquo;d like to offer this time is to be careful to read the instructions carefully. They included the specific folder where the files were located and I noticed several misinterpretations in the scripts. Some included a mandatory Path parameter and others had a default Path that was not the specified folder. Including an optional Path with the correct default would certainly be acceptable, but not those variations.<br>
The instructions also included some ambiguity about what the log file actually contains. Was the client IP address in the first column (as specified in the instructions) or in a different column (as presented in the example logs)? There were a number of entries that just searched the logs for IP addresses and returned all of them. This approach would not be able to distinguished between the client and server addresses, which would give a wrong answer. Another approach searched for the &ldquo;c-ip&rdquo; column, but this would only work if the log files were as in the samples. Another method, select the second IP address in a line would also only work on the sample log style. There weren&rsquo;t many entries that supported both file types, but one of them did it in a very concise manner, checking the first and ninth columns for an IP address and selecting the correct one.<br>
Most of the entries used<em>Sort-Object -Unique</em> or<em>Select-Object -Unique</em> to eliminate duplicates, which was the first approach that I thought of. There were several entries, however, that used alternate methods that I thought were quite clever applications of PowerShell technology: hash tables with the IP address as the key, and<em>Group-Object</em> on the IP address. Both options provided a fairly simple way to also report the instance count for each address.<br>
Returning an instance count sounds like an interesting option, but after thinking about it some more, I&rsquo;m not so sure. Counts of the number of sessions and the hits per session would be much more interesting than the raw hits count. But that&rsquo;s way, way beyond the scope of this event.<br>
Anyway, just one more event to go. I&rsquo;m expecting a spectacular finish!</p>
]]></content:encoded></item><item><title>"Super Secret" Snover Session at TechEd</title><link>https://powershell.org/articles/2013-05-29-super-secret-snover-session-at-teched/</link><guid>https://powershell.org/articles/2013-05-29-super-secret-snover-session-at-teched/</guid><pubDate>Wed, 29 May 2013 12:39:09 +0000</pubDate><description>&lt;p&gt;So what&amp;rsquo;s with the &lt;a href="http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/MDC-B302#fbid=nMfDOO99OjI"&gt;&amp;ldquo;super secret&amp;rdquo; PowerShell session&lt;/a&gt; being given by Jeffrey Snover at TechEd 2013?&lt;br&gt;
First, if you&amp;rsquo;ll be in New Orleans, plan to attend this. The deal is pretty simple: Microsoft has got a lot of information pertaining to v.Next under embargo, which means people can&amp;rsquo;t talk about it yet, or even tell you the title of the session. But trust me, if you&amp;rsquo;re interested in the world of DevOps (and if you use PowerShell, you are), you&amp;rsquo;ll want to be at this session. PowerShell MVPs were given a sneak peek at what Snover will be discussing, and it&amp;rsquo;ll frankly blow your mind. It will, over the long haul, put PowerShell in a completely new place - and you&amp;rsquo;ll want to get in on the ground floor.&lt;br&gt;
Like most sessions at TechEd, it appears as if they&amp;rsquo;ll be recording this, so even if you can&amp;rsquo;t attend in person be sure to check back once the recording is live. That usually takes a day or two after the talk itself.&lt;br&gt;
And spread the word a bit. There&amp;rsquo;s a bit of a worry that, because even the &lt;em&gt;title&lt;/em&gt; of the session won&amp;rsquo;t be announced until TechEd formally commences, folks won&amp;rsquo;t have much time to realize the session exists and it&amp;rsquo;ll go empty. We don&amp;rsquo;t want that to happen - as with any new developments in PowerShell, it&amp;rsquo;s crucial to get folks thinking about it early, to get their feedback early, and to start planning for it early.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>So what&rsquo;s with the<a href="http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/MDC-B302#fbid=nMfDOO99OjI">&ldquo;super secret&rdquo; PowerShell session</a> being given by Jeffrey Snover at TechEd 2013?<br>
First, if you&rsquo;ll be in New Orleans, plan to attend this. The deal is pretty simple: Microsoft has got a lot of information pertaining to v.Next under embargo, which means people can&rsquo;t talk about it yet, or even tell you the title of the session. But trust me, if you&rsquo;re interested in the world of DevOps (and if you use PowerShell, you are), you&rsquo;ll want to be at this session. PowerShell MVPs were given a sneak peek at what Snover will be discussing, and it&rsquo;ll frankly blow your mind. It will, over the long haul, put PowerShell in a completely new place - and you&rsquo;ll want to get in on the ground floor.<br>
Like most sessions at TechEd, it appears as if they&rsquo;ll be recording this, so even if you can&rsquo;t attend in person be sure to check back once the recording is live. That usually takes a day or two after the talk itself.<br>
And spread the word a bit. There&rsquo;s a bit of a worry that, because even the <em>title</em> of the session won&rsquo;t be announced until TechEd formally commences, folks won&rsquo;t have much time to realize the session exists and it&rsquo;ll go empty. We don&rsquo;t want that to happen - as with any new developments in PowerShell, it&rsquo;s crucial to get folks thinking about it early, to get their feedback early, and to start planning for it early.</p>
]]></content:encoded></item><item><title>Notes for Event 5</title><link>https://powershell.org/articles/2013-05-29-notes-for-event-5/</link><guid>https://powershell.org/articles/2013-05-29-notes-for-event-5/</guid><pubDate>Wed, 29 May 2013 12:27:33 +0000</pubDate><description>&lt;p&gt;Jan Egil, or Norwegian expert commentator/judge, has posted his learning notes for Event 5: &lt;a href="http://blog.powershell.no/2013/05/28/2013-scripting-games-learning-points-from-event-5/"&gt;http://blog.powershell.no/2013/05/28/2013-scripting-games-learning-points-from-event-5/&lt;/a&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Jan Egil, or Norwegian expert commentator/judge, has posted his learning notes for Event 5: <a href="http://blog.powershell.no/2013/05/28/2013-scripting-games-learning-points-from-event-5/">http://blog.powershell.no/2013/05/28/2013-scripting-games-learning-points-from-event-5/</a></p>
]]></content:encoded></item><item><title>Scripting Games Event 4 Winners</title><link>https://powershell.org/articles/2013-05-28-scripting-games-event-4-winners/</link><guid>https://powershell.org/articles/2013-05-28-scripting-games-event-4-winners/</guid><pubDate>Tue, 28 May 2013 13:32:27 +0000</pubDate><description>&lt;p&gt;We&amp;rsquo;re pleased to announce the winners for Event 4 of The Scripting Games 2013!&lt;br&gt;
Remember that Event 5 is now open for community voting, and that Event 6 opens up near the end of this week. That&amp;rsquo;ll be your last chance to contribute, and shortly after TechEd we&amp;rsquo;ll announce the overall winners. Good luck!&lt;br&gt;
Winners: You can log into &lt;a href="http://scriptinggames.org/"&gt;The Scripting Games Web site&lt;/a&gt; and go to your Profile page to see your prize. You will be given a prize redemption code and either a URL where you can redeem it, or an e-mail address of the prize provider (they will need the redemption code). All prizes must be claimed by the end of July 2013. I will list winners by username; if you used your e-mail address as your username, then a portion of that will be truncated for your privacy. Anyone can log in and check their Profile page to see if they&amp;rsquo;ve won a prize.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>We&rsquo;re pleased to announce the winners for Event 4 of The Scripting Games 2013!<br>
Remember that Event 5 is now open for community voting, and that Event 6 opens up near the end of this week. That&rsquo;ll be your last chance to contribute, and shortly after TechEd we&rsquo;ll announce the overall winners. Good luck!<br>
Winners: You can log into<a href="http://scriptinggames.org/">The Scripting Games Web site</a> and go to your Profile page to see your prize. You will be given a prize redemption code and either a URL where you can redeem it, or an e-mail address of the prize provider (they will need the redemption code). All prizes must be claimed by the end of July 2013. I will list winners by username; if you used your e-mail address as your username, then a portion of that will be truncated for your privacy. Anyone can log in and check their Profile page to see if they&rsquo;ve won a prize.</p><ul><li><p>Event 4 Beginner First Place: amello (free ebook from Manning)</p></li><li><p>Event 4 Beginner Second Place: jwoods@__.com (6 months video training from Interface)</p></li><li><p>Event 4 Beginner Third Place: Poshsg0606 (1 year of Phoneominal from Start-Automating)</p></li><li><p>Event 4 Advanced First Place: DawnVillejoin (free ebook from Manning)</p></li><li><p>Event 4 Advanced Second Place: adweigert (6 months video training from Interface)</p></li><li><p>Event 4 Advanced Third Place: JustinK70 (1 year of Phonenominal from Start-Automating)</p></li><li><p>Event 4 Beginner Top CrowdScore: taygibb (free ebook from Manning)</p></li><li><p>Event 4 Advanced Top CrowdScore: mikefrobbins (free ebook from Manning)</p></li></ul><p>These will be listed on our<a href="http://scriptinggames.org/winners.php">consolidated list of winners</a>, which includes links to the winning entries.<br>
Our CrowdScore winners get a selection of free ebooks from Manning, 1 month of video training from Interface, and $50 gift cards from SAPIEN; 1 prize per winner. Check your profile to see if you&rsquo;ve won!<br>
Congratulations to all of our winners! Note that our top three prizes in each category were awarded by our Mighty Panel of Celebrity Judges. Each judge nominated a first, second, and third place winner from the entries that our expert commentators identified as &ldquo;best.&rdquo; Those nominations were compiled, and in the event of a tie the earliest entry was deemed winner.</p>
]]></content:encoded></item><item><title>Event 4: My notes…</title><link>https://powershell.org/articles/2013-05-25-event-4-my-notes/</link><guid>https://powershell.org/articles/2013-05-25-event-4-my-notes/</guid><pubDate>Sat, 25 May 2013 21:09:10 +0000</pubDate><description>&lt;p&gt;Active Directory is one of those things I just love to work with. That&amp;rsquo;s why I was really looking forward to this event. As always, I learned few things, but still - seen some mistakes that I would like to highlight. As always - you can read about those both in &lt;a href="http://powershellpl.net/2013/05/25/scripting-games-moje-notatki-4/"&gt;Polish&lt;/a&gt; and in &lt;a href="http://becomelotr.wordpress.com/2013/05/25/event-4-my-notes/"&gt;English&lt;/a&gt;. Enjoy!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Active Directory is one of those things I just love to work with. That&rsquo;s why I was really looking forward to this event. As always, I learned few things, but still - seen some mistakes that I would like to highlight. As always - you can read about those both in<a href="http://powershellpl.net/2013/05/25/scripting-games-moje-notatki-4/">Polish</a> and in<a href="http://becomelotr.wordpress.com/2013/05/25/event-4-my-notes/">English</a>. Enjoy!</p>
]]></content:encoded></item><item><title>Scripting Games Week 4</title><link>https://powershell.org/articles/2013-05-24-scripting-games-week-4/</link><guid>https://powershell.org/articles/2013-05-24-scripting-games-week-4/</guid><pubDate>Fri, 24 May 2013 21:37:18 +0000</pubDate><description>&lt;p&gt;Again if you&amp;quot;™re participating in the games this year you&amp;quot;™ve already won!  If you&amp;quot;™re not and you&amp;quot;™re reading this post what are you doing!  I&amp;quot;™ve watched authors step there game up over the past month, and I can tell you from personal experience the games will make you better at your real job.  It&amp;quot;™s like sharpening an axe, an axe made of super juice that can automate the world 🙂&lt;br&gt;
**Well that&amp;rsquo;s clever!&lt;br&gt;
** I came across this script this morning.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Again if you"™re participating in the games this year you"™ve already won!  If you"™re not and you"™re reading this post what are you doing!  I"™ve watched authors step there game up over the past month, and I can tell you from personal experience the games will make you better at your real job.  It"™s like sharpening an axe, an axe made of super juice that can automate the world 🙂<br>
**Well that&rsquo;s clever!<br>
** I came across this script this morning.</p><h2 id="convertto-html--title-active-directory-audit--postcontent-" class="ps-heading">`$prop = Write-Output Name,Title,Department,LastLogonDate,PasswordLastSet,LockedOut,Enabled
Get-ADUser -Filter * -Properties $prop |
Get-Random -Count 20 | Select-Object $prop |
ConvertTo-Html -Title &ldquo;Active Directory Audit&rdquo; -PostContent "<a class="ps-heading-anchor" href="#convertto-html--title-active-directory-audit--postcontent-" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>$(Get-Date)" | Out-File C:\adresult.html
`Well formatted, simple concise, all around a very clean approach to the problem.  However the use of write-output threw me for a second.  I actually had to run it to see what was happening there, for a second I thought maybe there was yet another way to create a custom object in PowerShell.  Alas no, our intrepid author has simply deduced a way to avoid having to put quotes around the text.  Consider the following Prop1, and Prop2 are identical, but it"™s one less character using write-output.</p><p><code>$prop1 = Write-Output Name,Title,Department,LastLogonDate,PasswordLastSet,LockedOut,Enabled $prop2 = 'Name','Title','Department','LastLogonDate','PasswordLastSet','LockedOut','Enabled'</code>I"™m not saying we should start using write-output instead of quotation if for nothing other than syntax highlighting it"™s incorrect. However, this one time it"™s forgiven, and I"™m tipping my hat to you sir, well done.<br>
**Don"™t put spaces or dashes in your property names.<br>
** I"™ve seen this on and off throughout the games and I"™ll admit this one isn"™t a slam dunk, but that said don"™t do it. You"™re writing a script, camel case is the established standard for spaces. Yes the spaces do make it slightly easier to read, but at the cost of eliminate the reuse of the code.<br>
**Oh the Humanity.<br>
** Seriously read the damn help already. I could just fill this post with examples of simple mistakes that could have been avoided. Using the wrong cmdlet is one thing but take the following.</p><p><code>Get-Process | Sort-Object {Get-Random} | select -First 5</code>What"™s wrong with that picture? Well nothing except it"™s horribly inefficient since the Get-Random cmdlet has a count parameter!</p><p><code>Get-Process | Get-Random -Count 5</code>To the author You know who you are, everyone else read the help people!<br>
Light week this week, but I will say I am super excited about next weeks offerings it"™s a problem that tickles my kind of fancy, and I hope you all have as much fun solving it as I did.<br>
~Glenn</p>
]]></content:encoded></item><item><title>The new PowerShell Class is Coming to a CPLS Near You!</title><link>https://powershell.org/articles/2013-05-24-the-new-powershell-class-is-coming-to-a-cpls-near-you/</link><guid>https://powershell.org/articles/2013-05-24-the-new-powershell-class-is-coming-to-a-cpls-near-you/</guid><pubDate>Fri, 24 May 2013 21:00:09 +0000</pubDate><description>&lt;p&gt;Looking for a great getting-started PowerShell class? Or perhaps you&amp;rsquo;d like to send a colleague or peer to some PowerShell &amp;ldquo;zero to hero&amp;rdquo; training?&lt;br&gt;
We&amp;rsquo;ve just finished the official beta-teach of Microsoft&amp;rsquo;s 10961, Automating Administration with Windows PowerShell, and it went _great. _The sequencing of the class was spot-on, and we had an absolutely incredible group of students. Many were n00bs, which was perfect; a couple had &amp;ldquo;some&amp;rdquo; shell experience but wanted to learn &amp;ldquo;the right way.&amp;rdquo; And they did.&lt;br&gt;
Through a series of 12 modules, you&amp;rsquo;re led through the basics all the way up to writing your own script. The grand semi-finale has you creating a script that provisions a brand-new, freshly-installed Server Core instance - all without logging on to that instance at all. The high moment for me was when one student, after struggling a bit to get started on the provisioning lab, concluded with a &amp;ldquo;well, that did it.&amp;rdquo; Everything came together for him: command discovery, help, scripting, variables, remoting, &lt;em&gt;all&lt;/em&gt; of it. He &lt;em&gt;did&lt;/em&gt; the task, from scratch, with practically no help. He&amp;rsquo;s _there. _&lt;br&gt;
10961 replaces MS course 10325, and it will soon be supplemented by a Microsoft Courseware Marketplace title that goes further into scripting, error handling, debugging, and more&amp;hellip; what I&amp;rsquo;ve taken to calling _toolmaking. _We&amp;rsquo;ll hopefully continue to refresh both courses as PowerShell evolves.&lt;br&gt;
So call your local Microsoft Certified Partner - Learning Systems (&amp;ldquo;training center&amp;rdquo;) and see when they&amp;rsquo;re offering 10961. A bit of caution: this is a class where, unfortunately, an inexperienced MCT will be really challenged. While the course book is a full, almost-500-page book (you&amp;rsquo;re welcome), it&amp;rsquo;s tightly timed and you&amp;rsquo;ll definitely want to check the credentials and experience of whatever trainer is running the class. You can&amp;rsquo;t just &amp;ldquo;read the slides&amp;rdquo; to stay a module ahead of the students on this one.&lt;br&gt;
This class is &lt;em&gt;strongly&lt;/em&gt; based upon _Learn Windows PowerShell 3.0 in a Month of Lunches, _in terms of how the material is presented, although the sequence and narrative was altered a bit to better accommodate Microsoft requirements and classroom logistics. I&amp;rsquo;m &lt;em&gt;really&lt;/em&gt; proud of how the course turned out - so if you&amp;rsquo;ve got folks who need some PowerShell training, tell &amp;rsquo;em to look it up. Many CPLS centers offer remote training, too, meaning you can attend from the comfort of your own home or office.&lt;br&gt;
If you take the class, I&amp;rsquo;d love to hear what you think.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Looking for a great getting-started PowerShell class? Or perhaps you&rsquo;d like to send a colleague or peer to some PowerShell &ldquo;zero to hero&rdquo; training?<br>
We&rsquo;ve just finished the official beta-teach of Microsoft&rsquo;s 10961, Automating Administration with Windows PowerShell, and it went _great. _The sequencing of the class was spot-on, and we had an absolutely incredible group of students. Many were n00bs, which was perfect; a couple had &ldquo;some&rdquo; shell experience but wanted to learn &ldquo;the right way.&rdquo; And they did.<br>
Through a series of 12 modules, you&rsquo;re led through the basics all the way up to writing your own script. The grand semi-finale has you creating a script that provisions a brand-new, freshly-installed Server Core instance - all without logging on to that instance at all. The high moment for me was when one student, after struggling a bit to get started on the provisioning lab, concluded with a &ldquo;well, that did it.&rdquo; Everything came together for him: command discovery, help, scripting, variables, remoting, <em>all</em> of it. He <em>did</em> the task, from scratch, with practically no help. He&rsquo;s _there. _<br>
10961 replaces MS course 10325, and it will soon be supplemented by a Microsoft Courseware Marketplace title that goes further into scripting, error handling, debugging, and more&hellip; what I&rsquo;ve taken to calling _toolmaking. _We&rsquo;ll hopefully continue to refresh both courses as PowerShell evolves.<br>
So call your local Microsoft Certified Partner - Learning Systems (&ldquo;training center&rdquo;) and see when they&rsquo;re offering 10961. A bit of caution: this is a class where, unfortunately, an inexperienced MCT will be really challenged. While the course book is a full, almost-500-page book (you&rsquo;re welcome), it&rsquo;s tightly timed and you&rsquo;ll definitely want to check the credentials and experience of whatever trainer is running the class. You can&rsquo;t just &ldquo;read the slides&rdquo; to stay a module ahead of the students on this one.<br>
This class is <em>strongly</em> based upon _Learn Windows PowerShell 3.0 in a Month of Lunches, _in terms of how the material is presented, although the sequence and narrative was altered a bit to better accommodate Microsoft requirements and classroom logistics. I&rsquo;m <em>really</em> proud of how the course turned out - so if you&rsquo;ve got folks who need some PowerShell training, tell &rsquo;em to look it up. Many CPLS centers offer remote training, too, meaning you can attend from the comfort of your own home or office.<br>
If you take the class, I&rsquo;d love to hear what you think.</p>
]]></content:encoded></item><item><title>Scripting Games 2013: Event 4 Notes</title><link>https://powershell.org/articles/2013-05-23-scripting-games-2013-event-4-notes/</link><guid>https://powershell.org/articles/2013-05-23-scripting-games-2013-event-4-notes/</guid><pubDate>Fri, 24 May 2013 01:21:11 +0000</pubDate><description>&lt;p&gt;It is all downhill from here folks! Event 4 is in the books and we only have 2 more to go! Everyone has been doing an outstanding job with their submissions and it is becoming clear that people are learning new things and showing some great techniques with their code.&lt;br&gt;
Of course, this doesn&amp;rsquo;t mean that there isn&amp;rsquo;t room for improvement with some submissions to make them even better or just some simple mistakes that can be cleaned up to make average submissions into amazing submissions. With that, its time to dive into my notes&amp;quot;¦ You can check out the rest of this article &lt;a href="http://learn-powershell.net/2013/05/23/scripting-games-2013-event-4-notes/"&gt;here&lt;/a&gt;.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>It is all downhill from here folks! Event 4 is in the books and we only have 2 more to go! Everyone has been doing an outstanding job with their submissions and it is becoming clear that people are learning new things and showing some great techniques with their code.<br>
Of course, this doesn&rsquo;t mean that there isn&rsquo;t room for improvement with some submissions to make them even better or just some simple mistakes that can be cleaned up to make average submissions into amazing submissions. With that, its time to dive into my notes"¦ You can check out the rest of this article<a href="http://learn-powershell.net/2013/05/23/scripting-games-2013-event-4-notes/">here</a>.</p>
]]></content:encoded></item><item><title>Event 4 Notes</title><link>https://powershell.org/articles/2013-05-23-event-4-notes/</link><guid>https://powershell.org/articles/2013-05-23-event-4-notes/</guid><pubDate>Thu, 23 May 2013 15:10:15 +0000</pubDate><description>&lt;p&gt;Loved seeing &lt;strong&gt;[OutputType([PSObject])]&lt;/strong&gt; in an entry this morning&amp;hellip; that helps the help system document what your script produces. It&amp;rsquo;s a shame it doesn&amp;rsquo;t work well with custom type names (since those are a bit of a fake-out on the object), but it&amp;rsquo;s an attention to detail I appreciate.&lt;br&gt;
I &lt;strong&gt;am&lt;/strong&gt; seeing a little bit of misunderstandings. Keep in mind that the lastLogonTimestamp attribute in AD is the one that replicates, although there is a long possible delay in that replication. There are other &amp;ldquo;last logged on&amp;rdquo; attributes that &lt;em&gt;don&amp;rsquo;t&lt;/em&gt; replicate so you can&amp;rsquo;t rely on them unless you&amp;rsquo;re querying every DC (pretty inefficient).&lt;br&gt;
Hey, one thing to think about: sometimes simpler is better. For example, instead of adding a dozen lines to check and see if a module exists and can be loaded, just add a #requires comment for that module. Let the shell do that work and spew an error if the module isn&amp;rsquo;t present. It&amp;rsquo;ll even force-load the module into memory. Saves lots of steps.&lt;br&gt;
Hey, don&amp;rsquo;t declare functions as &lt;strong&gt;global:Do-This&lt;/strong&gt;. It&amp;rsquo;s a neat trick, but you&amp;rsquo;re polluting the shell&amp;rsquo;s global scope. Plan to write in-scope functions and make them a script module, so they can be loaded and unloaded. From the Games perspective, &amp;ldquo;whatever,&amp;rdquo; but in the real world&amp;hellip; don&amp;rsquo;t pollute the global scope.&lt;br&gt;
A comment I saw: &amp;ldquo;You should check to make sure the module isn&amp;rsquo;t loaded before loading it again.&amp;rdquo; Disagree. The shell does this for you when you use Import-Module. But, doc your module dependency in a #requires, and you won&amp;rsquo;t have to worry about the module. In fact, the whole theme of &amp;ldquo;checking to see if the AD module is loaded&amp;rdquo; appears to be a major point of commenting. I&amp;rsquo;m a fan of &amp;ldquo;easier&amp;rdquo; and a 1-line &lt;strong&gt;#requires -module ActiveDirectory&lt;/strong&gt; is far easier to write and maintain than, say, and entire function designed specifically to load the ActiveDirectory module.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Loved seeing <strong>[OutputType([PSObject])]</strong> in an entry this morning&hellip; that helps the help system document what your script produces. It&rsquo;s a shame it doesn&rsquo;t work well with custom type names (since those are a bit of a fake-out on the object), but it&rsquo;s an attention to detail I appreciate.<br>
I <strong>am</strong> seeing a little bit of misunderstandings. Keep in mind that the lastLogonTimestamp attribute in AD is the one that replicates, although there is a long possible delay in that replication. There are other &ldquo;last logged on&rdquo; attributes that <em>don&rsquo;t</em> replicate so you can&rsquo;t rely on them unless you&rsquo;re querying every DC (pretty inefficient).<br>
Hey, one thing to think about: sometimes simpler is better. For example, instead of adding a dozen lines to check and see if a module exists and can be loaded, just add a #requires comment for that module. Let the shell do that work and spew an error if the module isn&rsquo;t present. It&rsquo;ll even force-load the module into memory. Saves lots of steps.<br>
Hey, don&rsquo;t declare functions as <strong>global:Do-This</strong>. It&rsquo;s a neat trick, but you&rsquo;re polluting the shell&rsquo;s global scope. Plan to write in-scope functions and make them a script module, so they can be loaded and unloaded. From the Games perspective, &ldquo;whatever,&rdquo; but in the real world&hellip; don&rsquo;t pollute the global scope.<br>
A comment I saw: &ldquo;You should check to make sure the module isn&rsquo;t loaded before loading it again.&rdquo; Disagree. The shell does this for you when you use Import-Module. But, doc your module dependency in a #requires, and you won&rsquo;t have to worry about the module. In fact, the whole theme of &ldquo;checking to see if the AD module is loaded&rdquo; appears to be a major point of commenting. I&rsquo;m a fan of &ldquo;easier&rdquo; and a 1-line <strong>#requires -module ActiveDirectory</strong> is far easier to write and maintain than, say, and entire function designed specifically to load the ActiveDirectory module.</p>
]]></content:encoded></item><item><title>Judge notes for Event 4</title><link>https://powershell.org/articles/2013-05-23-judge-notes-for-event-4/</link><guid>https://powershell.org/articles/2013-05-23-judge-notes-for-event-4/</guid><pubDate>Thu, 23 May 2013 14:56:59 +0000</pubDate><description>&lt;p&gt; Wow! That&amp;rsquo;s the only word I can think of to describe the submissions this time. I&amp;rsquo;m really impressed with the approaches taken to solve this problem. The only thing that could have been better is quitting when the ActiveDirectory module or the Quest snapin weren&amp;rsquo;t found. I chalked that up to not having experience with an actual audit where no answer is not acceptable, so I didn&amp;rsquo;t count against it when evaluating the scripts. But, on this point kudos to the one script that tested for the AD module, then the Quest snapin, and fell back to the ADSI accelerator if neither were found.&lt;br&gt;
&lt;strong&gt;Beginner entries&lt;/strong&gt;&lt;br&gt;
For me, the best entries were those that had the shortest pipelines. Those of you who used &lt;em&gt;Get-Random -Count 20 -InputObject (Get-ADUser&amp;hellip;) | Select &amp;hellip; | ConvertTo-Html | Out-File&lt;/em&gt; had the shortest. And those who used &lt;em&gt;Get-ADUser | Get-Random -Count 20&lt;/em&gt; were a close second.&lt;br&gt;
A couple of entries had something that at first I thought was silly. But, instead, it offers a learning opportunity. Here&amp;rsquo;s the code fragment: &lt;em&gt;Get-ADUser -Filter {ObjectClass -eq &amp;lsquo;User&amp;rsquo;}&lt;/em&gt;. Paying attention to what the cmdlet does saves a lot of typing, not only here where the filter is redundant, but also when entering other parameters. For example, a similar extra effort occurs when default properties are explicitly listed in a -Properties parameter.&lt;br&gt;
&lt;strong&gt;Advanced entries&lt;/strong&gt;&lt;br&gt;
As mentioned, the best entries were those that fell back to the [ADSI] accelerator when the AD module or the Quest snapin weren&amp;rsquo;t found. Making this kind of check and fallback is pretty important when responding to audit requests. This reminds me of a case where I actually had to respond to an audit request with the actual last logon date in a domain with mixed W2K3, W2K8, and W2K8R2 domain controllers. The default choice was to use the AD module, but since we had to check each domain controller (there were 72 of them), it turned out to be a real pain determining which method to use on each of them. In the end, we decided to install the Quest tools on the audit server and just avoid the issue.&lt;br&gt;
There were several different methods used to verify the presence of the AD module before trying to load it. Most of them were actually more work that really necessary. The reason for this is that the Import-Module cmdlet does not return an error if the module has already been loaded. Thus, the easiest test would be:&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p> Wow! That&rsquo;s the only word I can think of to describe the submissions this time. I&rsquo;m really impressed with the approaches taken to solve this problem. The only thing that could have been better is quitting when the ActiveDirectory module or the Quest snapin weren&rsquo;t found. I chalked that up to not having experience with an actual audit where no answer is not acceptable, so I didn&rsquo;t count against it when evaluating the scripts. But, on this point kudos to the one script that tested for the AD module, then the Quest snapin, and fell back to the ADSI accelerator if neither were found.<br><strong>Beginner entries</strong><br>
For me, the best entries were those that had the shortest pipelines. Those of you who used<em>Get-Random -Count 20 -InputObject (Get-ADUser&hellip;) | Select &hellip; | ConvertTo-Html | Out-File</em> had the shortest. And those who used<em>Get-ADUser | Get-Random -Count 20</em> were a close second.<br>
A couple of entries had something that at first I thought was silly. But, instead, it offers a learning opportunity. Here&rsquo;s the code fragment:<em>Get-ADUser -Filter {ObjectClass -eq &lsquo;User&rsquo;}</em>. Paying attention to what the cmdlet does saves a lot of typing, not only here where the filter is redundant, but also when entering other parameters. For example, a similar extra effort occurs when default properties are explicitly listed in a -Properties parameter.<br><strong>Advanced entries</strong><br>
As mentioned, the best entries were those that fell back to the [ADSI] accelerator when the AD module or the Quest snapin weren&rsquo;t found. Making this kind of check and fallback is pretty important when responding to audit requests. This reminds me of a case where I actually had to respond to an audit request with the actual last logon date in a domain with mixed W2K3, W2K8, and W2K8R2 domain controllers. The default choice was to use the AD module, but since we had to check each domain controller (there were 72 of them), it turned out to be a real pain determining which method to use on each of them. In the end, we decided to install the Quest tools on the audit server and just avoid the issue.<br>
There were several different methods used to verify the presence of the AD module before trying to load it. Most of them were actually more work that really necessary. The reason for this is that the Import-Module cmdlet does not return an error if the module has already been loaded. Thus, the easiest test would be:</p><p><code>Try { Import-Module ActiveDirectory -ErrorAction Stop $Users = Get-ADUser ... } Catch { Write-Error "AD Module not available" # Fall back to ADSI to get User data }</code>The same is true for Add-PSSnapin for PowerShell 3, but in V2, it generates an error with &ldquo;because it is already added&rdquo; in $Error[0].Exception.Message. So, you can use something similar to check for that.<br>
To close out this set of comments, here&rsquo;s something to think about. The topic is embedded, or local, functions in a master function. Question 1: should you even go through the trouble of writing a local function if it&rsquo;s only going used one time? Question 2: since the local function will execute in a controlled environment, does it need to be an advanced function with comments and parameter validation, or would a simple function make more sense?<br>
Until next time: keep up the great work!!</p>
]]></content:encoded></item><item><title>Want a premier PowerShell class in your area next year? Help me make it happen.</title><link>https://powershell.org/articles/2013-05-23-want-a-premier-powershell-class-in-your-area-next-year-help-me-make-it-happen/</link><guid>https://powershell.org/articles/2013-05-23-want-a-premier-powershell-class-in-your-area-next-year-help-me-make-it-happen/</guid><pubDate>Thu, 23 May 2013 14:18:50 +0000</pubDate><description>&lt;p&gt;We&amp;rsquo;re putting together our schedule for 2014 (yes, already), and we&amp;rsquo;re looking to hold premier-level PowerShell master classes throughout the world. But&amp;hellip; we need your help.&lt;br&gt;
If you&amp;rsquo;ve got a really top-notch training center in your area that might be interested in working with us, &lt;a href="https://powershell.org/contact-us/"&gt;contact me&lt;/a&gt;. We&amp;rsquo;ll need the name of someone there - the training manager, the marketing manager, someone like that. We co-market our classes, but rely on a local center to market to their existing customer base as well. These &lt;em&gt;are&lt;/em&gt; premium classes, and they do go for a premium price, so the center has to be comfortable marketing that kind of class. We&amp;rsquo;re not the run-of-the-mill &amp;ldquo;official curriculum;&amp;rdquo; my Master Class packs in around eleven days of &amp;ldquo;normal&amp;rdquo; training, covering toolmaking, scripting, and advanced topics as well as the introductory-level stuff. _&lt;br&gt;
_&lt;br&gt;
International contacts are fine, and in fact it&amp;rsquo;s something I&amp;rsquo;m excited to get going, as international classes also help me set up future PowerShell Forum and PowerShell Saturday events in a country or region.&lt;br&gt;
So think about your area and see if we might be a fit, and if you&amp;rsquo;ve got a really top-notch training center you can put us in touch with!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>We&rsquo;re putting together our schedule for 2014 (yes, already), and we&rsquo;re looking to hold premier-level PowerShell master classes throughout the world. But&hellip; we need your help.<br>
If you&rsquo;ve got a really top-notch training center in your area that might be interested in working with us,<a href="https://powershell.org/contact-us/">contact me</a>. We&rsquo;ll need the name of someone there - the training manager, the marketing manager, someone like that. We co-market our classes, but rely on a local center to market to their existing customer base as well. These <em>are</em> premium classes, and they do go for a premium price, so the center has to be comfortable marketing that kind of class. We&rsquo;re not the run-of-the-mill &ldquo;official curriculum;&rdquo; my Master Class packs in around eleven days of &ldquo;normal&rdquo; training, covering toolmaking, scripting, and advanced topics as well as the introductory-level stuff. _<br>
_<br>
International contacts are fine, and in fact it&rsquo;s something I&rsquo;m excited to get going, as international classes also help me set up future PowerShell Forum and PowerShell Saturday events in a country or region.<br>
So think about your area and see if we might be a fit, and if you&rsquo;ve got a really top-notch training center you can put us in touch with!</p>
]]></content:encoded></item><item><title>Jan Egil's Event 4 Notes</title><link>https://powershell.org/articles/2013-05-22-jan-egils-event-4-notes/</link><guid>https://powershell.org/articles/2013-05-22-jan-egils-event-4-notes/</guid><pubDate>Wed, 22 May 2013 15:47:46 +0000</pubDate><description>&lt;p&gt;Jan offers some perspective on Event 4 at &lt;a href="http://blog.powershell.no/2013/05/22/2013-scripting-games-learning-points-from-event-4/"&gt;http://blog.powershell.no/2013/05/22/2013-scripting-games-learning-points-from-event-4/&lt;/a&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Jan offers some perspective on Event 4 at <a href="http://blog.powershell.no/2013/05/22/2013-scripting-games-learning-points-from-event-4/">http://blog.powershell.no/2013/05/22/2013-scripting-games-learning-points-from-event-4/</a></p>
]]></content:encoded></item><item><title>ValidateScript for Beginners</title><link>https://powershell.org/articles/2013-05-21-validatescript-for-beginners/</link><guid>https://powershell.org/articles/2013-05-21-validatescript-for-beginners/</guid><pubDate>Tue, 21 May 2013 18:03:27 +0000</pubDate><description>&lt;p&gt;There&amp;quot;™s been a lot of chatter about in Scripting Games 2013 blog posts about the ValidateScript attribute. The chatter is, appropriately, confined to the advanced events &amp;ldquo;“ this sort of thing is not expected in a one-liner. But I thought I&amp;rdquo;™d take a minute and demystify it &amp;ldquo;“ and discuss an issue that it raises about when input should be rejected.&lt;br&gt;
Let&amp;rdquo;™s start with a quick description of ValidateScript and its siblings. For help, see &lt;a href="http://go.microsoft.com/fwlink/?LinkID=135173"&gt;about_functions_advanced_parameters&lt;/a&gt;.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>There"™s been a lot of chatter about in Scripting Games 2013 blog posts about the ValidateScript attribute. The chatter is, appropriately, confined to the advanced events &ldquo;“ this sort of thing is not expected in a one-liner. But I thought I&rdquo;™d take a minute and demystify it &ldquo;“ and discuss an issue that it raises about when input should be rejected.<br>
Let&rdquo;™s start with a quick description of ValidateScript and its siblings. For help, see<a href="http://go.microsoft.com/fwlink/?LinkID=135173">about_functions_advanced_parameters</a>.</p><h2 id="what-is-validatescript" class="ps-heading">What is ValidateScript?<a class="ps-heading-anchor" href="#what-is-validatescript" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>ValidateScript and its siblings are<em>parameter validation attributes</em>. These attributes are statements that are added to the parameter definition. They tell Windows PowerShell to examine the parameter values that are used when the function is called and determine whether the parameter values meet some specified conditions. In particular, ValidateScript lets you write a script block to test the conditions that the values must satisfy. Windows PowerShell runs the validation script on the parameter values and, if the script returns $False, it throws a terminating error.<br>
Before we get to the details, let"™s talk about why you"™d want to use something like this. The answer is simplicity. &ldquo;What!!?!,&rdquo; you say, incredulously? The syntax of this thing looks like a sampler of Windows PowerShell enclosures. There"™s a square bracket &ldquo;[&rdquo; or two &ldquo;]&rdquo;, a pair of parentheses &ldquo;( )&rdquo; and even some curly braces &ldquo;{  }&rdquo;. So it doesn"™t look simple.<br>
But once you get over the syntax, you realize that putting the parameter value validation into the parameter definition means that you don"™t need to test the parameter value in your script. Instead, the Windows PowerShell engine tests the parameter value and you can use the script to do scripty things.</p><h1 id="using-validatescript" class="ps-heading">Using ValidateScript<a class="ps-heading-anchor" href="#using-validatescript" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><p>Here"™s what I mean. Here"™s a silly function that will serve as our example.</p><p><code>function Get-EventDate { Param($EventDate) if ($EventDate -is [DateTime] -and $EventDate -gt (Get-Date)) {"The event is happening on $EventDate."} else {Write-Error "Event date must be a DateTime object</code>
that represents a date in the future."}
}
`The Get-EventDate function has a $EventDate parameter. If the value of the $EventDate parameter is a DateTime object and it"™s later than now, the function writes a nice sentence with the date to the console or host program. But, if the value of $EventDate is not a DateTime object, or it"™s not a future date, the function generates an error. (To be complete, this info would be in the Help for the function.)<br>
But much of this little function is wrapped around validating the value of the $EventDate parameter. So let"™s see if we can get Windows PowerShell to validate it for us.<br>
In this version, we add a parameter value type enclosed in square brackets ([DateTime]) on the line before the parameter name ($EventDate).<br>
But that"™s enough to allow us to delete the &ldquo;if $EventDate &ldquo;“is [DateTime]&rdquo; from the If statement and from the error message.</p><p><code>function Get-EventDate { Param( [DateTime] $EventDate ) if ($EventDate -gt (Get-Date)) {"The event is happening on $EventDate."} else { Write-Error "Event date must represents a future date."} }</code>Let&rdquo;™s make sure it works. I"™ll send it a process object instead of a date. And, sure enough, Windows PowerShell generates an error explaining that it can"™t convert (&ldquo;process argument transformation&rdquo; &ldquo;“ oy!) a process object to a DateTime object.</p><p>`PS C:&gt; Get-EventDate -EventDate (Get-Process PowerShell)
Get-EventDate : Cannot process argument transformation on parameter
&lsquo;EventDate&rsquo;. Cannot convert the &ldquo;System.Diagnostics.Process (powershell)&rdquo;
value of type &ldquo;System.Diagnostics.Process&rdquo; to type &ldquo;System.DateTime&rdquo;.
At line:15 char:26</p><ul><li>Get-EventDate -EventDate (Get-Process PowerShell)
+                          ~~~~~~~~~~~~~~~~~~~~~~~~</li><li>CategoryInfo          : InvalidData: (:) [Get -EventDate],
ParameterBindingArgumentTransformationException</li><li>FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-EventDate
`Now, let&rdquo;™s get Windows PowerShell to test the other date condition for us. Here"™s where ValidateScript comes in.<br>
The syntax is a bit wonky. ValidateScript is enclosed in square brackets: [ValidateScript]. Its parameter is enclosed in parentheses: [ValidateScript( )] and the parameter value is a script block, complete with curly braces: [ValidateScript({ Your-script-goes-here })]. I can never remember this, so I use an ISE snippet or copy it from<a href="http://go.microsoft.com/fwlink/?LinkID=135173">about_functions_advanced_parameters</a>.<br>
But aside from the syntax, ValidateScript is easy to use. I just moved the (-gt (Get-Date)) from the script into the ValidateScript script block. Now, I can eliminate the error message, too.<br>
In the script block, &ldquo;$<em>&rdquo; represents the parameter value. If a parameter takes a collection (more than one) of objects, &ldquo;$</em>&rdquo; represents each value in the collection, which is tested one at a time &ldquo;“ no need for a Foreach-Object command.</li></ul><p><code>function Get-EventDate { Param( [ValidateScript({$_ -gt (Get-Date)})] [DateTime] $EventDate ) "The event is happening on $EventDate." }</code>When a parameter value fails a test, ValidateScript generates a terminating error. If the parameter value takes a collection, like a list of dates, and any one of the dates fails the test, ValidateScript throws an error that stops the script, even if all other dates pass the test.<br>
Let&rdquo;™s test by sending it a date in the past. (Today"™s date would generate the same error.) The error message explains (in more words that I could use) that the date failed the validation test.<br>
It"™s not a great error message, but it"™s the best we could do, because Windows PowerShell just executes the validation script in the script block. It can"™t guess your intent.</p><p>`PS C:&gt; Get-EventDate -EventDate (Get-Date -Month 9 -Day 21 -Year 2007)
Get-EventDate : Cannot validate argument on parameter &lsquo;EventDate&rsquo;.
The &ldquo;$_ -gt (Get-Date)&rdquo; validation script for the argument with value
&ldquo;9/21/2007 5:36:36 PM&rdquo; did not return true. Determine why the validation
script failed and then try the command again.
At line:1 char:26</p><ul><li>Get-EventDate -EventDate (Get-Date -Month 9 -Day 21 -Year 2007)
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</li><li>CategoryInfo          : InvalidData: (:) [Get-EventDate], ParameterBindingValidationException</li><li>FullyQualifiedErrorId : ParameterArgumentValidationError,Get-EventDate
`And, just for kicks, let"™s pass it a date in the future. This one works.</li></ul><p><code>PS C:\ &gt; Get-EventDate -EventDate (Get-Date -Month 9 -Day 21 -Year 2013) The event is happening on 09/21/2013 18:00:50.</code>## ValidateScript in Advanced Functions</p><p>This is the sort of clever thing that the advanced folks are doing. For example, here"™s the parameter section from Toni"™s totally terrific Archival Atrocity solution.</p><p><code>[CmdletBinding()] param( [ValidateScript({ Test-Path $_ -PathType Container })] [string]$LogPath="C:\Application\Log", [Parameter(Mandatory=$true)] [ValidateScript({ Test-Path "$LogPath\*" -Include $_ -PathType Container })] [string[]]$ApplicationLogFolder, [Parameter(Mandatory=$true)] [ValidateScript({ Test-Path $_ -PathType Container })] [string]$DestinationPath, [int]$Period=90 )</code>We"™re not even in the function statements yet, but we already know for sure that the values of the $LogPath, $ApplicationLog, and DestinationPath parameters are folders (not files), and the full path to these folders already exists in the file system. Not bad! Excellent, really. Clever enough to win second prize in the Nobel Prizes of PowerShell scripting. (Congratulations, Toni!)<br>
In fact, almost all of the advanced scripts used validation parameters. Take a peek. Keep a copy of<a href="http://go.microsoft.com/fwlink/?LinkID=135173">about_functions_advanced_parameters</a> nearby.</p><h2 id="should-we-use-validatescript" class="ps-heading">Should we use ValidateScript?<a class="ps-heading-anchor" href="#should-we-use-validatescript" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>This is very clever scripting, but is it a good idea? It"™s easier for the author and easier to maintain, because the conditions are in a predictable place.<br>
But, is this the right thing to do for users? I don"™t know the answer, but I think that we, as a community, need to consider the question.<br>
Jeffrey Snover, the Windows PowerShell grand architect, wisely proclaims that Windows PowerShell differs from other languages in that scripts should &ldquo;just work.&rdquo; Windows PowerShell scripts should make the user successful.<br>
The language goes to all ends in its pursuit of this principle. When you send the wrong type of parameter value to a cmdlet, Windows PowerShell tries to convert the value to the right type. It returns an error only when its attempts to convert fail.<br>
In Windows PowerShell 3.0, if you send it a collection of object and ask for a property that the collection doesn"™t have, Windows PowerShell checks to see if the objects in the collection have that property and, if they do, it returns the property value. (Try: (Get-Process).Name ).<br>
If you ask Windows PowerShell 3.0 how many items are in an empty object, it tells you 0, even though empty objects don"™t have a Count or Length property.</p><p><code>PS C:\&gt; $zoo = $null PS C:\&gt; $zoo.Count 0</code>Many scripts, including those we"™ve seen in these esteemed Games, have elaborate try-catch syntax to capture errors and create a pleasant user experience.<br>
So, given that background, should we encourage scripting techniques that throw errors to users, instead of making them successful? And, in particular, errors that cannot provide very helpful error messages?<br>
Personally, I prefer scripts that optimize the user experience, instead of the authoring experience. In the Get-EventDate example, where I planned to write an error anyway, ValidateScript is probably a cleaner alternative. But in the Archival Atrocity script, it would have been a much better user experience to create a directory if it didn"™t already exist.<br>
On the other hand, if I were writing a script only for myself, I would keep it strict. I would prefer the error message to the risk that I just created a directory structure for a typo.<br>
What do you think? Should we create community guidance for using validation attributes?</p>
]]></content:encoded></item><item><title>Scripting Games Event 3 Winners</title><link>https://powershell.org/articles/2013-05-21-scripting-games-event-3-winners/</link><guid>https://powershell.org/articles/2013-05-21-scripting-games-event-3-winners/</guid><pubDate>Tue, 21 May 2013 14:41:53 +0000</pubDate><description>&lt;p&gt;We&amp;rsquo;re pleased to announce the winners for Event 3 of The Scripting Games 2013!&lt;br&gt;
Winners: You can log into &lt;a href="http://scriptinggames.org/"&gt;The Scripting Games Web site&lt;/a&gt; and go to your Profile page to see your prize. You will be given a prize redemption code and either a URL where you can redeem it, or an e-mail address of the prize provider (they will need the redemption code). All prizes must be claimed by the end of July 2013. I will list winners by username; if you used your e-mail address as your username, then a portion of that will be truncated for your privacy. Anyone can log in and check their Profile page to see if they&amp;rsquo;ve won a prize.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Our hosting company is doing some maintenance on their admin site, so it may be a day or two before redemption codes appear in your Scripting Games profile. Appreciate your patience.&lt;br&gt;
And seriously, you&amp;rsquo;re killing me with the usernames. Heh.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>We&rsquo;re pleased to announce the winners for Event 3 of The Scripting Games 2013!<br>
Winners: You can log into<a href="http://scriptinggames.org/">The Scripting Games Web site</a> and go to your Profile page to see your prize. You will be given a prize redemption code and either a URL where you can redeem it, or an e-mail address of the prize provider (they will need the redemption code). All prizes must be claimed by the end of July 2013. I will list winners by username; if you used your e-mail address as your username, then a portion of that will be truncated for your privacy. Anyone can log in and check their Profile page to see if they&rsquo;ve won a prize.<br><strong>Note:</strong> Our hosting company is doing some maintenance on their admin site, so it may be a day or two before redemption codes appear in your Scripting Games profile. Appreciate your patience.<br>
And seriously, you&rsquo;re killing me with the usernames. Heh.</p><ul><li><p>Event 3 Beginner First Place: TechieSponge (free ebook from Manning)</p></li><li><p>Event 3 Beginner Second Place: LittleBunnyFooFoo (6 months video training from Interface)</p></li><li><p>Event 3 Beginner Third Place: chadmcauley (1 year of Phoneominal from Start-Automating)</p></li><li><p>Event 3 Advanced First Place: glenn.faustino (free ebook from Manning)</p></li><li><p>Event 3 Advanced Second Place: mikefrobbins (6 months video training from Interface)</p></li><li><p>Event 3 Advanced Third Place: CarloM (1 year of Phonenominal from Start-Automating)</p></li><li><p>Event 3 Beginner Top CrowdScore: LittleBunnyFooFoo (free ebook from Manning)</p></li><li><p>Event 3 Advanced Top CrowdScore: mikefrobbins (free ebook from Manning)</p></li></ul><p>These will be listed on our<a href="http://scriptinggames.org/winners.php">consolidated list of winners</a>, which includes links to the winning entries.<br>
Our CrowdScore winners get a selection of free ebooks from Manning, 1 month of video training from Interface, and $50 gift cards from SAPIEN; 1 prize per winner. Check your profile to see if you&rsquo;ve won!<br>
Congratulations to all of our winners! Note that our top three prizes in each category were awarded by our Mighty Panel of Celebrity Judges. Each judge nominated a first, second, and third place winner from the entries that our expert commentators identified as &ldquo;best.&rdquo; Those nominations were compiled, and in the event of a tie the earliest entry was deemed winner.</p>
]]></content:encoded></item><item><title>Some Event 3 Notes</title><link>https://powershell.org/articles/2013-05-18-some-event-3-notes/</link><guid>https://powershell.org/articles/2013-05-18-some-event-3-notes/</guid><pubDate>Sat, 18 May 2013 14:23:25 +0000</pubDate><description>&lt;p&gt;I didn&amp;rsquo;t see anyone (although I&amp;rsquo;ll admit I haven&amp;rsquo;t checked every entry) using my EnhancedHTML module from &lt;em&gt;Creating HTML Reports in PowerShell.&lt;/em&gt; I am ensaddened.&lt;br&gt;
But man, Event 3 shows that you can really do well by learning a wee bit of HTML. Knowing an H2 and HR tag makes for much pretty results. Take it as career advice.&lt;br&gt;
As a nitpick, don&amp;rsquo;t use Convert as a function verb unless all the function is going to do is convert something. It shouldn&amp;rsquo;t &amp;ldquo;Get&amp;rdquo; as well. That said, because this event wants a single function that both gets and converts&amp;hellip; which is something I&amp;rsquo;d ordinarily avoid packing into one function&amp;hellip; no big. It&amp;rsquo;s interesting to see the function names folks picked out.&lt;br&gt;
Folks, &lt;strong&gt;test your scripts.&lt;/strong&gt; Seriously.&lt;br&gt;
I kinda giggled when I saw this comment in an entry:&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I didn&rsquo;t see anyone (although I&rsquo;ll admit I haven&rsquo;t checked every entry) using my EnhancedHTML module from<em>Creating HTML Reports in PowerShell.</em> I am ensaddened.<br>
But man, Event 3 shows that you can really do well by learning a wee bit of HTML. Knowing an H2 and HR tag makes for much pretty results. Take it as career advice.<br>
As a nitpick, don&rsquo;t use Convert as a function verb unless all the function is going to do is convert something. It shouldn&rsquo;t &ldquo;Get&rdquo; as well. That said, because this event wants a single function that both gets and converts&hellip; which is something I&rsquo;d ordinarily avoid packing into one function&hellip; no big. It&rsquo;s interesting to see the function names folks picked out.<br>
Folks,<strong>test your scripts.</strong> Seriously.<br>
I kinda giggled when I saw this comment in an entry:</p><p><code># I'd like to Splat this but I don't know how / ran out of time</code>Heh. In general, this is like a cooking show. If you know your food doesn&rsquo;t taste good, don&rsquo;t bring it to the judges. And if you do bring it to them, don&rsquo;t tell them all the cool toppings you were going to add. Just give them what you made.<br>
Note to self: Don&rsquo;t write scenarios that require HTML. It messes up the Scripting Games Web site. Duh.<br>
You know, overall, I&rsquo;m seeing good stuff. I ran through some of the low-scoring entries and didn&rsquo;t see anything that didn&rsquo;t deserve a lowered score. If you constructed your own HTML instead of using ConvertTo-HTML, you pretty much got universally dinged, and I can understand and support that philosophy.<br>
Oh, and ConvertTo-HTML doesn&rsquo;t output to stdout, whoever wrote that. It writes to the pipeline. Big difference.<br>
Folks, when using Get-WmiObject,<em>use the -Filter parameter.</em> Don&rsquo;t get<em>everything</em> and pipe it to Where-Object. Get the filtering done early - this is a huge performance concept.<br>
This was interesting:</p><p><code>[Parameter(Mandatory=$True,ValueFromPipeline=$True)] [ValidateScript({Test-Connection -ComputerName $_ -Quiet -Count 2})] [STRING[]]$ComputerName,</code>I&rsquo;m entirely unsure how I feel about this. I like the idea. I keep telling people than a Ping doesn&rsquo;t really tell you anything when you&rsquo;re about to use WMI, though. If the computer responds, WMI might still fail; if the computer doesn&rsquo;t respond, WMI might still succeed. A ping is not useful diagnostic information for WMI connections. I understand the desire to try and eliminate the WMI timeout, but you&rsquo;re not doing so. What if I block ICMP traffic but not WMI traffic - a very common thing at a lot of my clients? Just bear that in mind.<br>
We&rsquo;re done with Hungarian notation ($objDisk, $strComputer). Time to move on.<br>
Commenters: Dudes, you need to read. For example, this:</p><blockquote><p>When localhost, an IP address, or an alias is provided, the actual computer name is not displayed on the web page and the file name is also incorrect. Consider using one of the properties from the WMI class that has the computer name instead of what the user provided on input.</p></blockquote><p>Was next to a 1-star vote. Totally inappropriate. 1 star, as the voting page clearly indicates, is when the script is totally non-functional. &ldquo;Bad entry - does not function at all&rdquo; is what it says under 1 star. This comment was on a working script. Maybe it didn&rsquo;t fulfill every requirement, but seriously, you&rsquo;d<em>fire a guy</em> whose script simply put an IP address instead of a computer name? No. This was a 3-star script according to the guidelines.<br>
Anyway&hellip; things are looking great. On to Event 4, which opens for voting real soon!</p>
]]></content:encoded></item><item><title>Your Weekend Games Report</title><link>https://powershell.org/articles/2013-05-18-your-weekend-games-report/</link><guid>https://powershell.org/articles/2013-05-18-your-weekend-games-report/</guid><pubDate>Sat, 18 May 2013 14:05:18 +0000</pubDate><description>&lt;p&gt;It&amp;rsquo;s been a crazy-busy week for me, so I&amp;rsquo;m just getting caught up here. I&amp;rsquo;m off observing the beta-teach of the new 10961A PowerShell 3 class in Phoenix next week, but I&amp;rsquo;ll be keeping an eye on the Games.&lt;br&gt;
So let&amp;rsquo;s run some numbers.&lt;br&gt;
The Games have 2092 users at present, along with 10960 scores and 5412 comments. There are 849 total entries.&lt;br&gt;
Regarding Event 3, we have 109 Advanced entries and 122 Beginner entries. The average beginner score is 2.8416, and the advanced score is 2.8512. Darn close.&lt;br&gt;
Site traffic is up to 25,000 visits from 18,200 unique visitors, for a total of 56,000 page views and a poo-load of bandwidth. I should have Event 3 winners posted on Tuesday sometime.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>It&rsquo;s been a crazy-busy week for me, so I&rsquo;m just getting caught up here. I&rsquo;m off observing the beta-teach of the new 10961A PowerShell 3 class in Phoenix next week, but I&rsquo;ll be keeping an eye on the Games.<br>
So let&rsquo;s run some numbers.<br>
The Games have 2092 users at present, along with 10960 scores and 5412 comments. There are 849 total entries.<br>
Regarding Event 3, we have 109 Advanced entries and 122 Beginner entries. The average beginner score is 2.8416, and the advanced score is 2.8512. Darn close.<br>
Site traffic is up to 25,000 visits from 18,200 unique visitors, for a total of 56,000 page views and a poo-load of bandwidth. I should have Event 3 winners posted on Tuesday sometime.</p>
]]></content:encoded></item><item><title>Meet the Scripting Games Judges: Olver Lipkau</title><link>https://powershell.org/articles/2013-05-18-meet-the-scripting-games-judges-olver-lipkau/</link><guid>https://powershell.org/articles/2013-05-18-meet-the-scripting-games-judges-olver-lipkau/</guid><pubDate>Sat, 18 May 2013 13:36:13 +0000</pubDate><description>&lt;p&gt;I have been working for AtoS, formaly Siemens IT Solutions and Services, for 6 years as a IT Consultant.&lt;br&gt;
I was 15 when I started scripting. First only batch scripts to automate simple things. With time the scriptt grew in complexity and languages. VBS, AutoIt, AHK and finally PowerShell, which superseeded all others. PowerShell became a passion and became more and more a daily thing.&lt;br&gt;
I was invited to be a judge for the Scripting Games in 2011, 2012 and now 2013.&lt;br&gt;
You are welcome to visit my Blog at &lt;a href="http://oliver.lipkau.net/blog"&gt;http://oliver.lipkau.net/blog&lt;/a&gt; and check out what I have been up to.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I have been working for AtoS, formaly Siemens IT Solutions and Services, for 6 years as a IT Consultant.<br>
I was 15 when I started scripting. First only batch scripts to automate simple things. With time the scriptt grew in complexity and languages. VBS, AutoIt, AHK and finally PowerShell, which superseeded all others. PowerShell became a passion and became more and more a daily thing.<br>
I was invited to be a judge for the Scripting Games in 2011, 2012 and now 2013.<br>
You are welcome to visit my Blog at<a href="http://oliver.lipkau.net/blog">http://oliver.lipkau.net/blog</a> and check out what I have been up to.</p>
]]></content:encoded></item><item><title>Event 3: My notes…</title><link>https://powershell.org/articles/2013-05-17-event-3-my-notes/</link><guid>https://powershell.org/articles/2013-05-17-event-3-my-notes/</guid><pubDate>Fri, 17 May 2013 21:56:13 +0000</pubDate><description>&lt;p&gt;I&amp;rsquo;m almost done judging event 3, perfect time to share few thoughts about things I&amp;rsquo;ve seen in this event. A lot of great entries, but still few things that could have been done (in my opinion) better. If you want to know my general opinion - you can read it either in &lt;a href="http://becomelotr.wordpress.com/2013/05/17/event-3-my-notes/"&gt;English&lt;/a&gt; or in &lt;a href="http://powershellpl.net/2013/05/17/scripting-games-moje-notatki-3/"&gt;Polish&lt;/a&gt;. Enjoy!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I&rsquo;m almost done judging event 3, perfect time to share few thoughts about things I&rsquo;ve seen in this event. A lot of great entries, but still few things that could have been done (in my opinion) better. If you want to know my general opinion - you can read it either in<a href="http://becomelotr.wordpress.com/2013/05/17/event-3-my-notes/">English</a> or in<a href="http://powershellpl.net/2013/05/17/scripting-games-moje-notatki-3/">Polish</a>. Enjoy!</p>
]]></content:encoded></item><item><title>Scheduled PowerShell.org Maintenance May 17-18</title><link>https://powershell.org/articles/2013-05-16-scheduled-powershell-org-maintenance-may-17-18/</link><guid>https://powershell.org/articles/2013-05-16-scheduled-powershell-org-maintenance-may-17-18/</guid><pubDate>Fri, 17 May 2013 00:04:59 +0000</pubDate><description>&lt;p&gt;We&amp;rsquo;ll be doing some maintenance on the site Friday and Saturday, and it may be down for periods during the maintenance. Don&amp;rsquo;t panic. This will not affect access to The Scripting Games Web site at all.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>We&rsquo;ll be doing some maintenance on the site Friday and Saturday, and it may be down for periods during the maintenance. Don&rsquo;t panic. This will not affect access to The Scripting Games Web site at all.</p>
]]></content:encoded></item><item><title>Jan Egil's Event 3 Learning Points</title><link>https://powershell.org/articles/2013-05-16-jan-egils-event-3-learning-points/</link><guid>https://powershell.org/articles/2013-05-16-jan-egils-event-3-learning-points/</guid><pubDate>Thu, 16 May 2013 21:54:14 +0000</pubDate><description>&lt;p&gt;Another judge steps up with some tips! &lt;a href="http://blog.powershell.no/2013/05/16/2013-scripting-games-learning-points-from-event-3/"&gt;http://blog.powershell.no/2013/05/16/2013-scripting-games-learning-points-from-event-3/&lt;/a&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Another judge steps up with some tips!<a href="http://blog.powershell.no/2013/05/16/2013-scripting-games-learning-points-from-event-3/">http://blog.powershell.no/2013/05/16/2013-scripting-games-learning-points-from-event-3/</a></p>
]]></content:encoded></item><item><title>More Updates to the Scripting Games</title><link>https://powershell.org/articles/2013-05-16-more-updates-to-the-scripting-games/</link><guid>https://powershell.org/articles/2013-05-16-more-updates-to-the-scripting-games/</guid><pubDate>Thu, 16 May 2013 20:50:09 +0000</pubDate><description>&lt;p&gt;I&amp;rsquo;ve been making some more programming changes to the Scripting Games, based on folks&amp;rsquo; feedback. &lt;strong&gt;If you run into problems, please notify me via the Feedback Forums link at the bottom of every page on the site.&lt;/strong&gt; Use the email address provided. Don&amp;rsquo;t post a comment here, because I might not see it quickly.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Multiple comments per reviewer -&lt;/strong&gt; you can now leave multiple comments on an entry. Combined with the ability to mark your comment as pertaining to a line or range of lines, this should allow for more granular commenting.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Comment without voting -&lt;/strong&gt; you are now free to offer comments without offering a score.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Delete comments&lt;/strong&gt; - you can now delete the comments you have written.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;rsquo;m still plugging away at some IE9/10-related errors, which are causing the code reviewer/voter/commenter to not display on some entries. In the meantime, Safari, Chrome, and Firefox seem to be working fine.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I&rsquo;ve been making some more programming changes to the Scripting Games, based on folks&rsquo; feedback.<strong>If you run into problems, please notify me via the Feedback Forums link at the bottom of every page on the site.</strong> Use the email address provided. Don&rsquo;t post a comment here, because I might not see it quickly.</p><ul><li><strong>Multiple comments per reviewer -</strong> you can now leave multiple comments on an entry. Combined with the ability to mark your comment as pertaining to a line or range of lines, this should allow for more granular commenting.</li><li><strong>Comment without voting -</strong> you are now free to offer comments without offering a score.</li><li><strong>Delete comments</strong> - you can now delete the comments you have written.</li></ul><p>I&rsquo;m still plugging away at some IE9/10-related errors, which are causing the code reviewer/voter/commenter to not display on some entries. In the meantime, Safari, Chrome, and Firefox seem to be working fine.</p>
]]></content:encoded></item><item><title>Tobias' Notes for Event 3</title><link>https://powershell.org/articles/2013-05-16-tobias-notes-for-event-3/</link><guid>https://powershell.org/articles/2013-05-16-tobias-notes-for-event-3/</guid><pubDate>Thu, 16 May 2013 19:18:04 +0000</pubDate><description>&lt;p&gt;Tobias has some notes for Event 3 for you: &lt;a href="http://www.powertheshell.com/scripting-games-task-3-commentary/"&gt;http://www.powertheshell.com/scripting-games-task-3-commentary/&lt;/a&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Tobias has some notes for Event 3 for you:<a href="http://www.powertheshell.com/scripting-games-task-3-commentary/">http://www.powertheshell.com/scripting-games-task-3-commentary/</a></p>
]]></content:encoded></item><item><title>Judge notes for event 3</title><link>https://powershell.org/articles/2013-05-16-judge-notes-for-event-3/</link><guid>https://powershell.org/articles/2013-05-16-judge-notes-for-event-3/</guid><pubDate>Thu, 16 May 2013 15:33:16 +0000</pubDate><description>&lt;p&gt;This event&amp;rsquo;s entries are impressive. Scoring appears to be higher than in the earlier events, so this one must have been easier to solve. So this time, instead of talking about good and bad scripts, I&amp;rsquo;m going to comment on some of the techniques I saw.&lt;br&gt;
There was some &amp;ldquo;conversation&amp;rdquo; over whether Win32_Volume or Win32_LogicalDisk was the better approach to take. Fact is, either will return the requested data. So it really doesn&amp;rsquo;t matter which one you use. The controversy seemed to include misreading or misunderstanding the requirement of reporting on &amp;ldquo;local hard drives&amp;rdquo;, which implies that you need to use &lt;em&gt;-Filter &amp;ldquo;DriveType=3&amp;rdquo;&lt;/em&gt; (or equivalent) with either to eliminate network or CD/DVD drives.&lt;br&gt;
When passing a Path parameter into a function, it&amp;rsquo;s a good practice to include &lt;em&gt;[ValidateScript ({Test-Path -PathType Container})]&lt;/em&gt; in the definition to avoid having a file name passed in error. Doing the existence test for the path and creating it if necessary in the Begin section of the function would save some time over the various techniques used in the Process section.&lt;br&gt;
One thing to remember when using a CIMSession is to close it when you&amp;rsquo;ve finished using it. A couple other points to pay attention to include accounting for the DCOM/WSMAN options when looking at remote computers and including &lt;em&gt;#requires -version 3&lt;/em&gt; in scripts that might be run by other people on computers that might not have PowerShell 3 installed.&lt;br&gt;
Using a REGEX to validate a string parameter, such as a computer name, isn&amp;rsquo;t a bad idea, but it&amp;rsquo;s important to understand exactly what the match string means. As an example, some of the match strings included a pattern like this: &lt;em&gt;&amp;quot;[a-zA-Z0-9.-]&amp;quot;&lt;/em&gt;. This means all lower and upper case letters, any numeric digit, any character, or a minus sign. The any character (&amp;quot;.&amp;quot;) defeats the whole purpose of the match. It really should have been escaped to &amp;ldquo;.&amp;rdquo; to mean a period. This error would probably never appear due to the unlikelihood of a badly formatted computer name being fed into the function.&lt;br&gt;
Lastly, a caution when including an optional credentials parameter. It&amp;rsquo;s probably not a good idea to default it to an empty credential object &lt;em&gt;($Credential = [System.Management.Automation.PSCredential]::Empty)&lt;/em&gt;. If you do a &lt;em&gt;if ($Credential) {}&lt;/em&gt; call later in the script, it will always be $true and you may end up calling for the user to enter credentials far too many times. A better solution would be to check PSBoundParameters to see if a credential object was passed in.&lt;br&gt;
Hope these ideas help. Good luck in Event 4.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>This event&rsquo;s entries are impressive. Scoring appears to be higher than in the earlier events, so this one must have been easier to solve. So this time, instead of talking about good and bad scripts, I&rsquo;m going to comment on some of the techniques I saw.<br>
There was some &ldquo;conversation&rdquo; over whether Win32_Volume or Win32_LogicalDisk was the better approach to take. Fact is, either will return the requested data. So it really doesn&rsquo;t matter which one you use. The controversy seemed to include misreading or misunderstanding the requirement of reporting on &ldquo;local hard drives&rdquo;, which implies that you need to use<em>-Filter &ldquo;DriveType=3&rdquo;</em> (or equivalent) with either to eliminate network or CD/DVD drives.<br>
When passing a Path parameter into a function, it&rsquo;s a good practice to include<em>[ValidateScript ({Test-Path -PathType Container})]</em> in the definition to avoid having a file name passed in error. Doing the existence test for the path and creating it if necessary in the Begin section of the function would save some time over the various techniques used in the Process section.<br>
One thing to remember when using a CIMSession is to close it when you&rsquo;ve finished using it. A couple other points to pay attention to include accounting for the DCOM/WSMAN options when looking at remote computers and including<em>#requires -version 3</em> in scripts that might be run by other people on computers that might not have PowerShell 3 installed.<br>
Using a REGEX to validate a string parameter, such as a computer name, isn&rsquo;t a bad idea, but it&rsquo;s important to understand exactly what the match string means. As an example, some of the match strings included a pattern like this:<em>"[a-zA-Z0-9.-]"</em>. This means all lower and upper case letters, any numeric digit, any character, or a minus sign. The any character (".") defeats the whole purpose of the match. It really should have been escaped to &ldquo;.&rdquo; to mean a period. This error would probably never appear due to the unlikelihood of a badly formatted computer name being fed into the function.<br>
Lastly, a caution when including an optional credentials parameter. It&rsquo;s probably not a good idea to default it to an empty credential object<em>($Credential = [System.Management.Automation.PSCredential]::Empty)</em>. If you do a<em>if ($Credential) {}</em> call later in the script, it will always be $true and you may end up calling for the user to enter credentials far too many times. A better solution would be to check PSBoundParameters to see if a credential object was passed in.<br>
Hope these ideas help. Good luck in Event 4.</p>
]]></content:encoded></item><item><title>Scripting Games 2013: Event 3 Notes</title><link>https://powershell.org/articles/2013-05-15-scripting-games-2013-event-3-notes/</link><guid>https://powershell.org/articles/2013-05-15-scripting-games-2013-event-3-notes/</guid><pubDate>Thu, 16 May 2013 03:03:08 +0000</pubDate><description>&lt;p&gt;Wow, it is hard to believe that we are now halfway through the Scripting Games! As the events have progressed, I have seen a lot of improvement with the techniques as well as seeing new techniques that continue to impress me. On the flip side, I have seen some mistakes or assumptions when coding that cause a potential 5 star script to be a 2 or 3 star script. The best part about all of this is that we are all (yes, even the judges) learning new things that can only help to improve everyone&amp;quot;™s scripting knowledge. Check out the rest of the &lt;a href="http://learn-powershell.net/2013/05/15/scripting-games-2013-event-3-notes/"&gt;article here&lt;/a&gt;.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Wow, it is hard to believe that we are now halfway through the Scripting Games! As the events have progressed, I have seen a lot of improvement with the techniques as well as seeing new techniques that continue to impress me. On the flip side, I have seen some mistakes or assumptions when coding that cause a potential 5 star script to be a 2 or 3 star script. The best part about all of this is that we are all (yes, even the judges) learning new things that can only help to improve everyone"™s scripting knowledge. Check out the rest of the<a href="http://learn-powershell.net/2013/05/15/scripting-games-2013-event-3-notes/">article here</a>.</p>
]]></content:encoded></item><item><title>Meet the Scripting Games Judges: Bartek Bielawski</title><link>https://powershell.org/articles/2013-05-15-meet-the-scripting-games-judges-bartek-bielawski/</link><guid>https://powershell.org/articles/2013-05-15-meet-the-scripting-games-judges-bartek-bielawski/</guid><pubDate>Wed, 15 May 2013 21:18:14 +0000</pubDate><description>&lt;p&gt;Bartosz (Bartek) Bielawski is a busy IT Administrator with an international company, PAREXEL. He loves PowerShell and automation. That love earned him the honor of Microsoft MVP. He shares his knowledge mainly on his blogs: in English (&lt;a href="http://becomelotr.wordpress.com"&gt;http://becomelotr.wordpress.com&lt;/a&gt;) and Polish (&lt;a href="http://powershellpl.net"&gt;http://powershellpl.net&lt;/a&gt;) and through articles published in the Polish IT Professional (&lt;a href="http://it-professional.pl"&gt;http://it-professional.pl&lt;/a&gt;) magazine. He is co-author of PowerShell Deep Dives book (&lt;a href="http://www.manning.com/hicks/)"&gt;http://www.manning.com/hicks/)&lt;/a&gt;. He loves good code that takes advantage of PowerShell pipeline and advanced functions grouped in modules.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Bartosz (Bartek) Bielawski is a busy IT Administrator with an international company, PAREXEL. He loves PowerShell and automation. That love earned him the honor of Microsoft MVP. He shares his knowledge mainly on his blogs: in English (<a href="http://becomelotr.wordpress.com">http://becomelotr.wordpress.com</a>) and Polish (<a href="http://powershellpl.net">http://powershellpl.net</a>) and through articles published in the Polish IT Professional (<a href="http://it-professional.pl">http://it-professional.pl</a>) magazine. He is co-author of PowerShell Deep Dives book (<a href="http://www.manning.com/hicks/)">http://www.manning.com/hicks/)</a>. He loves good code that takes advantage of PowerShell pipeline and advanced functions grouped in modules.</p>
]]></content:encoded></item><item><title>Scripting Games Event 2 Winners</title><link>https://powershell.org/articles/2013-05-14-scripting-games-event-1-winners-1/</link><guid>https://powershell.org/articles/2013-05-14-scripting-games-event-1-winners-1/</guid><pubDate>Tue, 14 May 2013 15:22:41 +0000</pubDate><description>&lt;p&gt;We&amp;rsquo;re pleased to announce the winners for Event 2 of The Scripting Games 2013!&lt;br&gt;
Winners: You can log into &lt;a href="http://scriptinggames.org/"&gt;The Scripting Games Web site&lt;/a&gt; and go to your Profile page to see your prize. You will be given a prize redemption code and either a URL where you can redeem it, or an e-mail address of the prize provider (they will need the redemption code). All prizes must be claimed by the end of July 2013. I will list winners by username; if you used your e-mail address as your username, then a portion of that will be truncated for your privacy. Anyone can log in and check their Profile page to see if they&amp;rsquo;ve won a prize.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>We&rsquo;re pleased to announce the winners for Event 2 of The Scripting Games 2013!<br>
Winners: You can log into<a href="http://scriptinggames.org/">The Scripting Games Web site</a> and go to your Profile page to see your prize. You will be given a prize redemption code and either a URL where you can redeem it, or an e-mail address of the prize provider (they will need the redemption code). All prizes must be claimed by the end of July 2013. I will list winners by username; if you used your e-mail address as your username, then a portion of that will be truncated for your privacy. Anyone can log in and check their Profile page to see if they&rsquo;ve won a prize.</p><ul><li><p>Event 2 Beginner First Place: kurtdg (free ebook from Manning)</p></li><li><p>Event 2 Beginner Second Place: JayJay (6 months video training from Interface)</p></li><li><p>Event 2 Beginner Third Place: wesleyhaut (1 year of Phoneominal from Start-Automating)</p></li><li><p>Event 2 Advanced First Place:<em>Emin</em> (free ebook from Manning)</p></li><li><p>Event 2 Advanced Second Place: mikefrobbins (6 months video training from Interface)</p></li><li><p>Event 2 Advanced Third Place: SimonW (1 year of Phonenominal from Start-Automating)</p></li><li><p>Event 2 Beginner Top CrowdScore: taygibb (free ebook from Manning)</p></li><li><p>Event 2 Advanced Top CrowdScore: mikefrobbins (free ebook from Manning)</p></li></ul><p>These are now listed on our<a href="http://scriptinggames.org/winners.php">consolidated list of winners</a>, which includes links to the winning entries.<br>
Our CrowdScore winners get a selection of free ebooks from Manning, 1 month of video training from Interface, and $50 gift cards from SAPIEN; 1 prize per winner.</p><ul><li>CrowdScore Voter: SimonW</li><li>CrowdScore Voter: khopcroft</li><li>CrowdScore Voter: markashley1961</li><li>CrowdScore Voter: kbrucej</li><li>CrowdScore Voter: kraanr</li><li>CrowdScore Voter: takenow350@_.com</li></ul><p>Congratulations to all of our winners! Note that our top three prizes in each category were awarded by our Mighty Panel of Celebrity Judges. Each judge nominated a first, second, and third place winner from the entries that our expert commentators identified as &ldquo;best.&rdquo; Those nominations were compiled, and in the event of a tie the earliest entry was deemed winner.</p>
]]></content:encoded></item><item><title>Announcing the PowerShell Summit North America 2014</title><link>https://powershell.org/articles/2013-05-14-announcing-the-powershell-summit-north-america-2014/</link><guid>https://powershell.org/articles/2013-05-14-announcing-the-powershell-summit-north-america-2014/</guid><pubDate>Tue, 14 May 2013 14:39:11 +0000</pubDate><description>&lt;p&gt;The PowerShell Summit North America 2014 will be held April 28, 29, and 30 at the Meydenbauer Center on Northeast 6th Street in Bellevue, WA.&lt;br&gt;
Your membership in the PowerShell Summit also makes you a yearlong member of PowerShell.org, the online hub for the PowerShell community. Membership includes a daily continental breakfast, daily hot lunch, and three tracks of expert-led lectures and discussions. 2014 tracks include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;INTERNALS: Inner secrets of PowerShell, suitable for developers and admins alike.&lt;/li&gt;
&lt;li&gt;DEEP DIVES: Dig into technically rich topics related to the shell itself and broad administrative tasks.&lt;/li&gt;
&lt;li&gt;DOMAIN SPECIFIC: Focus on managing specific server products and technologies using the shell.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;[NB: For tax reasons, you become a &amp;ldquo;member&amp;rdquo; of the organization and go to our meeting as part of that; we don&amp;rsquo;t sell &amp;ldquo;tickets.&amp;rdquo;]&lt;br&gt;
&lt;strong&gt;Pricing&lt;/strong&gt; will range from $750-$950. We&amp;rsquo;d originally hoped to do a flat price, but the logistics of our venue is pushing this decision. So we&amp;rsquo;ll be offering discounted tickets first, and then moving up the price as we go. Get in early to get the cheap seats!&lt;br&gt;
If you choose to stay at one of our official hotels, you&amp;rsquo;ll enjoy a reduced room rate, complimentary in-room Internet, and a short 15-minute walk to the Meydenbauer Center. We recommend taking a shuttle from the airport (&lt;a href="http://bit.ly/ZNWGcw"&gt;http://bit.ly/ZNWGcw&lt;/a&gt; $20oneway; taxis $65+) instead of a rental car; parking is NOT complimentary.&lt;br&gt;
NEARBY HOTELS include: Sheraton (&lt;a href="http://bit.ly/10mVQog)"&gt;http://bit.ly/10mVQog)&lt;/a&gt;, Hilton (&lt;a href="http://bit.ly/YsQiq8)"&gt;http://bit.ly/YsQiq8)&lt;/a&gt;, and Red Lion (&lt;a href="http://bit.ly/10gXH8v)"&gt;http://bit.ly/10gXH8v)&lt;/a&gt;. All are adjacent to each other and are a .6 mile walk to the Meydenbauer Center. Courtyard by Marriott (&lt;a href="http://bit.ly/12RvG9a"&gt;http://bit.ly/12RvG9a&lt;/a&gt;) is across the street from the Meydenbauer Center. We do not yet have official room availability and rates.&lt;br&gt;
These hotels are also less than a 4-minute taxi ride (under $5oneway) to downtown Bellevue, full of retail, dining, bars, and nightlife. You will probably spend MORE on a rental car (around $100 best-case, plus parking fees and fuel).&lt;br&gt;
We will have a small-bandwidth Internet pipe available for WiFi use at the conference center. We recommend that you NOT rely on it for mission-critical or business-sensitive tasks, as it is a shared pipe and will likely have poor performance during peak usage.&lt;br&gt;
We are not currently planning to offer power outlets in rooms. You may NOT stretch power cords across walkways to plug in your laptop. We are seeking out a Power Sponsor - the cost to have enough power for everyone&amp;rsquo;s laptop is about $20,000 (it&amp;rsquo;s one way conference centers make their profits), so this is a significant expense.&lt;br&gt;
We are planning a brief private meet-and-greet reception for PowerShell.org, Inc. shareholders. We are also planning general evening events.&lt;br&gt;
MEMBERSHIP SALES WILL BEGIN IN JULY with a private announcement to our 2013 alumni and our shareholders. After that, we will offer a block of memberships to our TechLetter subscribers. These folks will have first dibs not only on the event, but also on our limited block of nearby and discounted hotel rooms. We will release subsequent blocks in 2013 and 2014 for the public.&lt;br&gt;
FULL DETAILS will always be available online at &lt;a href="http://PowerShellSummit.org"&gt;http://PowerShellSummit.org&lt;/a&gt; (this will redirect to the appropriate page for information and news).&lt;br&gt;
&lt;strong&gt;UPDATE&lt;/strong&gt;: I know there&amp;rsquo;s a bit of disappointment that we&amp;rsquo;re not &amp;ldquo;on campus.&amp;rdquo; First&amp;hellip; understand that we were a little under-the-radar in 2013, in terms of outside groups doing what we did in those particular locations. We also need to grow the event a bit in order to make it financially self-sustaining. And, the real clincher, no place &amp;ldquo;on campus&amp;rdquo; could accommodate us. However, &amp;ldquo;campus&amp;rdquo; (this is why I keep putting it in quotes) spans Redmond and Bellevue - we&amp;rsquo;re actually adjacent to Microsoft offices, in 2014, and we&amp;rsquo;re scheduling an evening event (community/team mixer, with team Q&amp;amp;A stations) in MS facilities. We&amp;rsquo;ll also try to wrangle a company store/museum visit (there&amp;rsquo;s a company Connector Shuttle that runs to Commons, which is where the store and museum are located). Most importantly, our location will ensure team participation - which is what doing this in the Seattle metro was all about. In fact, we&amp;rsquo;re planning expanded team participation, with the addition of team-led &amp;ldquo;lightning demos&amp;rdquo; that will highlight cool features and tricks, and which will be a prelude to that evening&amp;rsquo;s community/team mixer (so you can ask follow-up questions in smaller groups). So&amp;hellip; given all of the possible alternatives, we felt this was the best solution. After all, the main session content is just you sitting in a room - shouldn&amp;rsquo;t matter where that room is. The big thing for us is the team engagement, and the opportunity to do &lt;em&gt;fun&lt;/em&gt; stuff on campus, and we think we&amp;rsquo;ve got that nailed. More to come.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>The PowerShell Summit North America 2014 will be held April 28, 29, and 30 at the Meydenbauer Center on Northeast 6th Street in Bellevue, WA.<br>
Your membership in the PowerShell Summit also makes you a yearlong member of PowerShell.org, the online hub for the PowerShell community. Membership includes a daily continental breakfast, daily hot lunch, and three tracks of expert-led lectures and discussions. 2014 tracks include:</p><ul><li>INTERNALS: Inner secrets of PowerShell, suitable for developers and admins alike.</li><li>DEEP DIVES: Dig into technically rich topics related to the shell itself and broad administrative tasks.</li><li>DOMAIN SPECIFIC: Focus on managing specific server products and technologies using the shell.</li></ul><p>[NB: For tax reasons, you become a &ldquo;member&rdquo; of the organization and go to our meeting as part of that; we don&rsquo;t sell &ldquo;tickets.&rdquo;]<br><strong>Pricing</strong> will range from $750-$950. We&rsquo;d originally hoped to do a flat price, but the logistics of our venue is pushing this decision. So we&rsquo;ll be offering discounted tickets first, and then moving up the price as we go. Get in early to get the cheap seats!<br>
If you choose to stay at one of our official hotels, you&rsquo;ll enjoy a reduced room rate, complimentary in-room Internet, and a short 15-minute walk to the Meydenbauer Center. We recommend taking a shuttle from the airport (<a href="http://bit.ly/ZNWGcw">http://bit.ly/ZNWGcw</a> $20oneway; taxis $65+) instead of a rental car; parking is NOT complimentary.<br>
NEARBY HOTELS include: Sheraton (<a href="http://bit.ly/10mVQog)">http://bit.ly/10mVQog)</a>, Hilton (<a href="http://bit.ly/YsQiq8)">http://bit.ly/YsQiq8)</a>, and Red Lion (<a href="http://bit.ly/10gXH8v)">http://bit.ly/10gXH8v)</a>. All are adjacent to each other and are a .6 mile walk to the Meydenbauer Center. Courtyard by Marriott (<a href="http://bit.ly/12RvG9a">http://bit.ly/12RvG9a</a>) is across the street from the Meydenbauer Center. We do not yet have official room availability and rates.<br>
These hotels are also less than a 4-minute taxi ride (under $5oneway) to downtown Bellevue, full of retail, dining, bars, and nightlife. You will probably spend MORE on a rental car (around $100 best-case, plus parking fees and fuel).<br>
We will have a small-bandwidth Internet pipe available for WiFi use at the conference center. We recommend that you NOT rely on it for mission-critical or business-sensitive tasks, as it is a shared pipe and will likely have poor performance during peak usage.<br>
We are not currently planning to offer power outlets in rooms. You may NOT stretch power cords across walkways to plug in your laptop. We are seeking out a Power Sponsor - the cost to have enough power for everyone&rsquo;s laptop is about $20,000 (it&rsquo;s one way conference centers make their profits), so this is a significant expense.<br>
We are planning a brief private meet-and-greet reception for PowerShell.org, Inc. shareholders. We are also planning general evening events.<br>
MEMBERSHIP SALES WILL BEGIN IN JULY with a private announcement to our 2013 alumni and our shareholders. After that, we will offer a block of memberships to our TechLetter subscribers. These folks will have first dibs not only on the event, but also on our limited block of nearby and discounted hotel rooms. We will release subsequent blocks in 2013 and 2014 for the public.<br>
FULL DETAILS will always be available online at<a href="http://PowerShellSummit.org">http://PowerShellSummit.org</a> (this will redirect to the appropriate page for information and news).<br><strong>UPDATE</strong>: I know there&rsquo;s a bit of disappointment that we&rsquo;re not &ldquo;on campus.&rdquo; First&hellip; understand that we were a little under-the-radar in 2013, in terms of outside groups doing what we did in those particular locations. We also need to grow the event a bit in order to make it financially self-sustaining. And, the real clincher, no place &ldquo;on campus&rdquo; could accommodate us. However, &ldquo;campus&rdquo; (this is why I keep putting it in quotes) spans Redmond and Bellevue - we&rsquo;re actually adjacent to Microsoft offices, in 2014, and we&rsquo;re scheduling an evening event (community/team mixer, with team Q&amp;A stations) in MS facilities. We&rsquo;ll also try to wrangle a company store/museum visit (there&rsquo;s a company Connector Shuttle that runs to Commons, which is where the store and museum are located). Most importantly, our location will ensure team participation - which is what doing this in the Seattle metro was all about. In fact, we&rsquo;re planning expanded team participation, with the addition of team-led &ldquo;lightning demos&rdquo; that will highlight cool features and tricks, and which will be a prelude to that evening&rsquo;s community/team mixer (so you can ask follow-up questions in smaller groups). So&hellip; given all of the possible alternatives, we felt this was the best solution. After all, the main session content is just you sitting in a room - shouldn&rsquo;t matter where that room is. The big thing for us is the team engagement, and the opportunity to do<em>fun</em> stuff on campus, and we think we&rsquo;ve got that nailed. More to come.</p>
]]></content:encoded></item><item><title>Event 3: My way…</title><link>https://powershell.org/articles/2013-05-13-event-3-my-way/</link><guid>https://powershell.org/articles/2013-05-13-event-3-my-way/</guid><pubDate>Tue, 14 May 2013 07:09:35 +0000</pubDate><description>&lt;p&gt;Third event is open for voting, but as usual - before I see any of the scripts submitted by you, I&amp;rsquo;m posting my version. Tried to sneak in few tricks I&amp;rsquo;ve learned here and there, hope you will enjoy reading and will tell me why I&amp;rsquo;m wrong. 😉 You can find whole post &lt;a href="http://becomelotr.wordpress.com/2013/05/14/event-3-my-way/"&gt;here&lt;/a&gt;.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Third event is open for voting, but as usual - before I see any of the scripts submitted by you, I&rsquo;m posting my version. Tried to sneak in few tricks I&rsquo;ve learned here and there, hope you will enjoy reading and will tell me why I&rsquo;m wrong. 😉 You can find whole post<a href="http://becomelotr.wordpress.com/2013/05/14/event-3-my-way/">here</a>.</p>
]]></content:encoded></item><item><title>Scripting Games 2013: Event 2 Notes</title><link>https://powershell.org/articles/2013-05-12-scripting-games-2013-event-2-notes/</link><guid>https://powershell.org/articles/2013-05-12-scripting-games-2013-event-2-notes/</guid><pubDate>Mon, 13 May 2013 02:32:40 +0000</pubDate><description>&lt;p&gt;I spent some time last week and this weekend to compile a list of notes of what I have seen with the Event 2 submissions that could show improvement. I touched up on some items with my &lt;a href="http://learn-powershell.net/2013/05/08/scripting-games-2013-event-2-favorite-and-not-so-favorite/"&gt;previous article&lt;/a&gt; where I picked out some submissions that I liked and didn&amp;rsquo;t quite like but wanted to touch on a few more things. Some of this feels like a repeat of last week and even last years games, but that is Ok. This is all about learning and as long as everyone takes what all of the judges have been writing about, then there will be nothing but great improvements during the course of the games. &lt;a href="http://learn-powershell.net/2013/05/12/scripting-games-2013-event-2-notes/"&gt;Click here&lt;/a&gt; to go to continue reading this article.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I spent some time last week and this weekend to compile a list of notes of what I have seen with the Event 2 submissions that could show improvement. I touched up on some items with my<a href="http://learn-powershell.net/2013/05/08/scripting-games-2013-event-2-favorite-and-not-so-favorite/">previous article</a> where I picked out some submissions that I liked and didn&rsquo;t quite like but wanted to touch on a few more things. Some of this feels like a repeat of last week and even last years games, but that is Ok. This is all about learning and as long as everyone takes what all of the judges have been writing about, then there will be nothing but great improvements during the course of the games.<a href="http://learn-powershell.net/2013/05/12/scripting-games-2013-event-2-notes/">Click here</a> to go to continue reading this article.</p>
]]></content:encoded></item><item><title>People Who are Blogging About the 2013 Scripting Games</title><link>https://powershell.org/articles/2013-05-11-people-who-are-blogging-about-the-2013-scripting-games/</link><guid>https://powershell.org/articles/2013-05-11-people-who-are-blogging-about-the-2013-scripting-games/</guid><pubDate>Sat, 11 May 2013 23:13:49 +0000</pubDate><description>&lt;p&gt;I&amp;rsquo;m sure that most people can easily find any of the blogs of the official judges from the 2013 Scripting Games. I recommend reading those blogs whether you&amp;rsquo;re competing in the scripting games or not since there&amp;rsquo;s a wealth of great information contained in them. The best place to find those blogs if you don&amp;rsquo;t know already is the &lt;a href="https://powershell.org/category/announcements/scripting-games/judges-notes/"&gt;Judges Notes section&lt;/a&gt; under the &lt;a href="https://powershell.org/category/announcements/scripting-games/"&gt;Scripting Games area&lt;/a&gt; on &lt;a href="https://powershell.org/"&gt;PowerShell.org&lt;/a&gt; so there&amp;rsquo;s no reason to duplicate them here.&lt;br&gt;
There are also a number of people who are competing in the Scripting Games that are writing blog articles of their own blog sites. A couple of the ones that I&amp;rsquo;m aware of are listed below and while they&amp;rsquo;re my competition in the advanced class and have links promoting their Scripting Games entries in their blogs (I do the same thing),  I don&amp;rsquo;t mind promoting their blog articles because there&amp;rsquo;s some great information to be found in them. I&amp;rsquo;m actually glad they provided links to their entries because both of these guys are excellent PowerShell scripters and you could learn a lot from viewing their Scripting Games entries. Ultimately the scripting games is all about the community learning more about using PowerShell best practices in a friendly competition that&amp;rsquo;s just for fun. &lt;a href="http://mikefrobbins.com/2013/05/11/people-who-are-blogging-about-the-2013-scripting-games/"&gt;Click here&lt;/a&gt; to be redirected to the original post of this article on the author&amp;rsquo;s blog site where you can read the remainder of the article.&lt;br&gt;
µ&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I&rsquo;m sure that most people can easily find any of the blogs of the official judges from the 2013 Scripting Games. I recommend reading those blogs whether you&rsquo;re competing in the scripting games or not since there&rsquo;s a wealth of great information contained in them. The best place to find those blogs if you don&rsquo;t know already is the <a href="https://powershell.org/category/announcements/scripting-games/judges-notes/">Judges Notes section</a> under the <a href="https://powershell.org/category/announcements/scripting-games/">Scripting Games area</a> on <a href="https://powershell.org/">PowerShell.org</a> so there&rsquo;s no reason to duplicate them here.<br>
There are also a number of people who are competing in the Scripting Games that are writing blog articles of their own blog sites. A couple of the ones that I&rsquo;m aware of are listed below and while they&rsquo;re my competition in the advanced class and have links promoting their Scripting Games entries in their blogs (I do the same thing),  I don&rsquo;t mind promoting their blog articles because there&rsquo;s some great information to be found in them. I&rsquo;m actually glad they provided links to their entries because both of these guys are excellent PowerShell scripters and you could learn a lot from viewing their Scripting Games entries. Ultimately the scripting games is all about the community learning more about using PowerShell best practices in a friendly competition that&rsquo;s just for fun.<a href="http://mikefrobbins.com/2013/05/11/people-who-are-blogging-about-the-2013-scripting-games/">Click here</a> to be redirected to the original post of this article on the author&rsquo;s blog site where you can read the remainder of the article.<br>
µ</p>
]]></content:encoded></item><item><title>Changes in Scripting Games Displays</title><link>https://powershell.org/articles/2013-05-10-changes-in-scripting-games-displays/</link><guid>https://powershell.org/articles/2013-05-10-changes-in-scripting-games-displays/</guid><pubDate>Fri, 10 May 2013 23:52:49 +0000</pubDate><description>&lt;p&gt;I want to point out some changes that are being made to the Games:&lt;br&gt;
Effective immediately, entry author names and current scores will not be shown for events that are still open for new votes. This is intended to help ensure everyone submitting a score isn&amp;rsquo;t influenced by other people. I&amp;rsquo;ve seen a bit of ganging-up that I&amp;rsquo;d rather not see.&lt;br&gt;
Archived events - those completely closed and for which prizes have been awarded - will display full information, including user names of comment authors.&lt;br&gt;
The new event viewer, which is currently under development, will display comment author names. These will be visible to an entry&amp;rsquo;s author immediately, and to the public once the event is no longer open for voting.&lt;br&gt;
Entry authors: This means you won&amp;rsquo;t be able to see your score while it&amp;rsquo;s still open for voting, unless you use the new beta viewer (which I&amp;rsquo;ll be wrapping up this weekend).&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I want to point out some changes that are being made to the Games:<br>
Effective immediately, entry author names and current scores will not be shown for events that are still open for new votes. This is intended to help ensure everyone submitting a score isn&rsquo;t influenced by other people. I&rsquo;ve seen a bit of ganging-up that I&rsquo;d rather not see.<br>
Archived events - those completely closed and for which prizes have been awarded - will display full information, including user names of comment authors.<br>
The new event viewer, which is currently under development, will display comment author names. These will be visible to an entry&rsquo;s author immediately, and to the public once the event is no longer open for voting.<br>
Entry authors: This means you won&rsquo;t be able to see your score while it&rsquo;s still open for voting, unless you use the new beta viewer (which I&rsquo;ll be wrapping up this weekend).</p>
]]></content:encoded></item><item><title>Scripting Games beta entry viewer</title><link>https://powershell.org/articles/2013-05-10-scripting-games-beta-entry-viewer/</link><guid>https://powershell.org/articles/2013-05-10-scripting-games-beta-entry-viewer/</guid><pubDate>Fri, 10 May 2013 19:43:04 +0000</pubDate><description>&lt;p&gt;If you&amp;rsquo;d like a quick peek at something, log into the &lt;a href="http://scriptinggames.org/"&gt;Scripting Games Web site&lt;/a&gt;, and go look at the entries in Event 1. Your URL should look like this:&lt;br&gt;
&lt;strong&gt;&lt;a href="http://scriptinggames.org/entrylist.php?eventid=11"&gt;http://scriptinggames.org/entrylist.php?eventid=11&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
Change it to this:&lt;br&gt;
&lt;strong&gt;&lt;a href="http://scriptinggames.org/entrylist_.php?eventid=11"&gt;http://scriptinggames.org/entrylist_.php?eventid=11&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
This is the new viewer I&amp;rsquo;m building. It isn&amp;rsquo;t rigged up to accept votes or comments, yet, but I&amp;rsquo;m working on that. It&amp;rsquo;s being developed for Firefox; I&amp;rsquo;ll test the other major browsers once it&amp;rsquo;s a bit more complete. This is under development, so it may be offline or unreliable. Don&amp;rsquo;t &lt;em&gt;tell&lt;/em&gt; me about it - I&amp;rsquo;m &lt;em&gt;already working on it&lt;/em&gt; .&lt;br&gt;
You can probably use this on Event 2 as well. The voting and commenting should be working. Note that you must vote before you can comment, and right now it&amp;rsquo;ll only accept one comment per person. That will probably remain the case for the current iteration of the Games based on some back-end dependencies. However, you CAN tie a comment to a particular line number or range of lines, and when viewing the comment it&amp;rsquo;ll highlight those lines. It&amp;rsquo;s pretty neat, I think.&lt;br&gt;
Oh, and I know the coloring on block comments is wonky. I need to dive into the color-er&amp;rsquo;s regexes and see if I can tweak that. Any regex wizards who want to volunteer to help with that, drop me a line. Right now the PowerShell syntax in the color-er is a little primitive. Actually, there are probably several regexes we could add to this to spruce up the listings.&lt;br&gt;
And yes, I know the comments now show the author&amp;rsquo;s user name. That&amp;rsquo;s been a big back-and-forth. I&amp;rsquo;m not a huge fan of anonymous commenting, and right now it&amp;rsquo;s just your username anyway. Hopefully nobody said anything truly offensive simply because they thought they were anonymous :).&lt;br&gt;
Back to work.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>If you&rsquo;d like a quick peek at something, log into the<a href="http://scriptinggames.org/">Scripting Games Web site</a>, and go look at the entries in Event 1. Your URL should look like this:<br><strong><a href="http://scriptinggames.org/entrylist.php?eventid=11">http://scriptinggames.org/entrylist.php?eventid=11</a></strong><br>
Change it to this:<br><strong><a href="http://scriptinggames.org/entrylist_.php?eventid=11">http://scriptinggames.org/entrylist_.php?eventid=11</a></strong><br>
This is the new viewer I&rsquo;m building. It isn&rsquo;t rigged up to accept votes or comments, yet, but I&rsquo;m working on that. It&rsquo;s being developed for Firefox; I&rsquo;ll test the other major browsers once it&rsquo;s a bit more complete. This is under development, so it may be offline or unreliable. Don&rsquo;t<em>tell</em> me about it - I&rsquo;m<em>already working on it</em> .<br>
You can probably use this on Event 2 as well. The voting and commenting should be working. Note that you must vote before you can comment, and right now it&rsquo;ll only accept one comment per person. That will probably remain the case for the current iteration of the Games based on some back-end dependencies. However, you CAN tie a comment to a particular line number or range of lines, and when viewing the comment it&rsquo;ll highlight those lines. It&rsquo;s pretty neat, I think.<br>
Oh, and I know the coloring on block comments is wonky. I need to dive into the color-er&rsquo;s regexes and see if I can tweak that. Any regex wizards who want to volunteer to help with that, drop me a line. Right now the PowerShell syntax in the color-er is a little primitive. Actually, there are probably several regexes we could add to this to spruce up the listings.<br>
And yes, I know the comments now show the author&rsquo;s user name. That&rsquo;s been a big back-and-forth. I&rsquo;m not a huge fan of anonymous commenting, and right now it&rsquo;s just your username anyway. Hopefully nobody said anything truly offensive simply because they thought they were anonymous :).<br>
Back to work.</p>
]]></content:encoded></item><item><title>Some notes on Event 2 Advanced</title><link>https://powershell.org/articles/2013-05-10-some-notes-on-event-2-advanced/</link><guid>https://powershell.org/articles/2013-05-10-some-notes-on-event-2-advanced/</guid><pubDate>Fri, 10 May 2013 16:17:32 +0000</pubDate><description>&lt;p&gt;I hate to seem negative, but I&amp;rsquo;ve noticed a few things about a number of the advanced entries that seem like folks didn&amp;rsquo;t read the instructions, or just weren&amp;rsquo;t careful about details.&lt;br&gt;
There were a surprising number of entries that had [string]$ComputerName instead of [string[]]$ComputerName in the params section and then went on to treat the parameter as if it were an array.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Somewhat related to the array issue, the problem statement indicated that there could be several files that had computer identification for piping into the solution. Several scripts went beyond the minimum by accepting a filename property to process those files directly. I don&amp;rsquo;t think that extension is out-of-bounds, but  scripts that accepted only filenames and excluded ComputerName input didn&amp;rsquo;t get my vote.&lt;/li&gt;
&lt;li&gt;The instructions asked for a &amp;ldquo;full help display&amp;rdquo;, but many of the entries had fairly limited documentation. One thing I especially missed was a .PARAMETER description.&lt;/li&gt;
&lt;li&gt;My last negative comment is about parameter names. Although there&amp;rsquo;s nothing in PowerShell to prevent it, best practices in parameter names should be followed. The parameter ought to be $ComputerName, not $Name, $Server, $Computer, etc. I know it&amp;rsquo;s easier with verbs and nouns because of the Get-Verb and Get-Noun cmdlets, but please pay attention to how you name your parameters.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On the whole, though I really liked the effort everyone put into their scripts. Those that exactly met the requirements were short, sweet, and to the point. There were several extensions that I also liked.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I hate to seem negative, but I&rsquo;ve noticed a few things about a number of the advanced entries that seem like folks didn&rsquo;t read the instructions, or just weren&rsquo;t careful about details.<br>
There were a surprising number of entries that had [string]$ComputerName instead of [string[]]$ComputerName in the params section and then went on to treat the parameter as if it were an array.</p><ul><li>Somewhat related to the array issue, the problem statement indicated that there could be several files that had computer identification for piping into the solution. Several scripts went beyond the minimum by accepting a filename property to process those files directly. I don&rsquo;t think that extension is out-of-bounds, but  scripts that accepted only filenames and excluded ComputerName input didn&rsquo;t get my vote.</li><li>The instructions asked for a &ldquo;full help display&rdquo;, but many of the entries had fairly limited documentation. One thing I especially missed was a .PARAMETER description.</li><li>My last negative comment is about parameter names. Although there&rsquo;s nothing in PowerShell to prevent it, best practices in parameter names should be followed. The parameter ought to be $ComputerName, not $Name, $Server, $Computer, etc. I know it&rsquo;s easier with verbs and nouns because of the Get-Verb and Get-Noun cmdlets, but please pay attention to how you name your parameters.</li></ul><p>On the whole, though I really liked the effort everyone put into their scripts. Those that exactly met the requirements were short, sweet, and to the point. There were several extensions that I also liked.</p><ul><li>Working with optional credentials. It was reasonable to assume that the script would be run using appropriate credentials, some of the scripts accepted alternate credentials for making the CIM or WMI queries. I consider it a best practice to log in and execute tasks at low permissions levels (standard user) and to use elevated credentials only on the specific commands that need them. Kudos also to those of you who accepted either a credentials object or a user name and found the credentials.</li><li>Using parallel execution to speed up the process. PowerShell provides runspaces, workspaces, and jobs to allow multiple commands to execute concurrently. Nothing in the event hinted at using parallelism, so I put these on my &ldquo;clever&rdquo; list.</li><li>Using PowerShell 3&rsquo;s CIM cmdlets. Using the new features of the latest version of PowerShell is quite good, especially when making use of the backwards compatibility features. I would have done this a bit differently than most, though. Instead of always using the Dcom session option, I would have opened a SimSession using a<em>try {WSMAN} Catch {DCOM}</em> and running the queries against the session.</li></ul><p>So, good work, everybody. Let&rsquo;s see what more we can learn in event 3.</p>
]]></content:encoded></item><item><title>Scripting Games Week 2: Formatting edition</title><link>https://powershell.org/articles/2013-05-10-scripting-games-week-2-formatting-edition/</link><guid>https://powershell.org/articles/2013-05-10-scripting-games-week-2-formatting-edition/</guid><pubDate>Fri, 10 May 2013 12:40:16 +0000</pubDate><description>&lt;p&gt;This time of the year always feels like someone is holding down the fast forward button.  I blinked and here we are Friday morning another week of scripts in the rear view.  I spent most of my week in the beginner class this week, and was greeted by a combination of beginners and scripters who weren&amp;quot;™t quite ready to step up to advanced.  More of the latter if I&amp;quot;™m to be honest.  This was a pleasant surprise as it&amp;quot;™s another sign of the continuing growth of our community.  Now on to the scripts I knew when I signed up to do this, that at least one of these weeks I&amp;quot;™d talk about formatting.  It&amp;quot;™s one of those best practices that you don&amp;quot;™t appreciate until you&amp;quot;™re asked to review someone else&amp;quot;™s code.&lt;br&gt;
&lt;strong&gt;Don&amp;quot;™t Crunch the Code, and for the love of all things, Hit Enter!&lt;/strong&gt;&lt;br&gt;
I did not deduct any points for readability, but you didn&amp;quot;™t make my good list either.  Personally I find it disrespectful to share an ungodly one-liner, but it&amp;quot;™s downright wrong if that single line has semicolons!  We&amp;quot;™re not printing these scripts the crunch gets us nothing. I&amp;quot;™m not going to call out the litany of scripts that were manually formatting the data directly which is even worse, but consider the following.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>This time of the year always feels like someone is holding down the fast forward button.  I blinked and here we are Friday morning another week of scripts in the rear view.  I spent most of my week in the beginner class this week, and was greeted by a combination of beginners and scripters who weren"™t quite ready to step up to advanced.  More of the latter if I"™m to be honest.  This was a pleasant surprise as it"™s another sign of the continuing growth of our community.  Now on to the scripts I knew when I signed up to do this, that at least one of these weeks I"™d talk about formatting.  It"™s one of those best practices that you don"™t appreciate until you"™re asked to review someone else"™s code.<br><strong>Don"™t Crunch the Code, and for the love of all things, Hit Enter!</strong><br>
I did not deduct any points for readability, but you didn"™t make my good list either.  Personally I find it disrespectful to share an ungodly one-liner, but it"™s downright wrong if that single line has semicolons!  We"™re not printing these scripts the crunch gets us nothing. I"™m not going to call out the litany of scripts that were manually formatting the data directly which is even worse, but consider the following.</p><p><code>Get-Content C:\IpList.txt | Foreach-Object { $Processor = Get-WmiObject -ComputerName $_ -NameSpace "Root\CIMV2" -Class "Win32_Processor"; $OpSystem = Get-WmiObject -ComputerName $_ -Namespace "Root\CIMV2" -Class "Win32_OperatingSystem"; New-Object -TypeName PSObject -Property @{ Name = $Processor.SystemName; Cores = $Processor.NumberOfCores; OS = $OpSystem.Caption; Version = $OpSystem.Version; Memory = $OpSystem.TotalVisibleMemorySize } }</code>This is an almost perfect solution and it"™s utilizing my next tip for this week already, but the formatting made it unnecessarily hard to read. Let just clean this up a bit by inserting a proper CR in place of all those semi-colons.</p><p><code>Get-Content C:\IpList.txt | Foreach-Object { $Processor = Get-WmiObject -ComputerName $_ -Class "Win32_Processor" $OpSystem = Get-WmiObject -ComputerName $_ -Class "Win32_OperatingSystem" New-Object -TypeName PSObject -Property @{ "Name" = $Processor.SystemName "Cores" = $Processor.NumberOfCores "OS" = $OpSystem.Caption "Version" = $OpSystem.Version "Memory" = $OpSystem.TotalVisibleMemorySize } }</code>Does anyone honestly not think the latter is better? The whitespace cost nothing at execution, and makes it an order of magnitude easier for a human being to read, process, and comprehend! I don"™t care what you do in your own scripts but when another human being is going to be asked to read it take a moment and format it. By the way for those in audience in love with the all-powerful one-liner both those examples are one-liners.<br><strong>That"™s Sooooo 2006!</strong><br>
Seriously, it"™s okay to use the latest features of the language! Heck how about we just agree to use the features from the last version! What am I talking about? object creation! Again I didn"™t take any points off for this, and you may have made my good list, but I didn"™t like it. Select-Object and Add-Member NoteProperty were how we built custom object in 2006 with PowerShell v1. PowerShell V2 added an extremely powerful &ldquo;“Property parameter to New-Object that completely removed the need for Add-Member, and PowerShell V3 introduced the [PSCustomObject] type accelerator that removed them all! Consider the following look back at the past six years of PowerShell Object Creation.</p><p>`# 2006
Get-Content .\IpList.txt | Foreach-Object {
$Processor = Get-WmiObject -ComputerName $_ -Class &ldquo;Win32_Processor&rdquo;
$OpSystem = Get-WmiObject -ComputerName $_ -Class &ldquo;Win32_OperatingSystem&rdquo;
New-Object -TypeName PSObject |
Add-Member -MemberType Noteproperty -Name &ldquo;Name&rdquo; -value $Processor.SystemName -PassThru |
Add-Member -MemberType Noteproperty -Name &ldquo;Cores&rdquo; -value $Processor.NumberOfCores -PassThru |
Add-Member -MemberType Noteproperty -Name &ldquo;OS&rdquo; -value $OpSystem.Caption -PassThru |
Add-Member -MemberType Noteproperty -Name &ldquo;Version&rdquo; -value $OpSystem.Version -PassThru |
Add-Member -MemberType Noteproperty -Name &ldquo;Memory&rdquo; -value $OpSystem.TotalVisibleMemorySize -PassThru
}</p><h1 id="2007-this-worked-in-2006-but-it-took-a-little-while-to-catch-on" class="ps-heading">2007 This worked in 2006, but it took a little while to catch on.<a class="ps-heading-anchor" href="#2007-this-worked-in-2006-but-it-took-a-little-while-to-catch-on" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><p>Get-Content .\IpList.txt | Foreach-Object {
$OpSystem = Get-WmiObject -ComputerName $_ -Class &ldquo;Win32_OperatingSystem&rdquo;
Get-WmiObject -ComputerName $_ -Class &ldquo;Win32_Processor&rdquo;|
Select-Object -Property SystemName, NumberOfCores,
@{&lsquo;Name&rsquo;=&ldquo;OS&rdquo;;&ldquo;Expression&rdquo;={$OpSystem.Caption}},
@{&lsquo;Name&rsquo;=&ldquo;Version&rdquo;;&ldquo;Expression&rdquo;={$OpSystem.Version}},
@{&lsquo;Name&rsquo;=&ldquo;Memory&rdquo;;&ldquo;Expression&rdquo;={$OpSystem.TotalVisibleMemorySize}}
}</p><h1 id="2009" class="ps-heading">2009<a class="ps-heading-anchor" href="#2009" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><p>Get-Content .\IpList.txt | Foreach-Object {
$Processor = Get-WmiObject -ComputerName $_ -Class &ldquo;Win32_Processor&rdquo;
$OpSystem = Get-WmiObject -ComputerName $_ -Class &ldquo;Win32_OperatingSystem&rdquo;
New-Object -TypeName PSObject -Property @{
&ldquo;Name&rdquo; = $Processor.SystemName
&ldquo;Cores&rdquo; = $Processor.NumberOfCores
&ldquo;OS&rdquo; = $OpSystem.Caption
&ldquo;Version&rdquo;= $OpSystem.Version
&ldquo;Memory&rdquo; = $OpSystem.TotalVisibleMemorySize
}
}</p><h1 id="2012" class="ps-heading">2012<a class="ps-heading-anchor" href="#2012" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><p>Get-Content .\IpList.txt | Foreach-Object {
$Processor = Get-WmiObject -ComputerName $_ -Class &ldquo;Win32_Processor&rdquo;
$OpSystem = Get-WmiObject -ComputerName $_ -Class &ldquo;Win32_OperatingSystem&rdquo;
[PSCustomObject]@{
&ldquo;Name&rdquo; = $Processor.SystemName
&ldquo;Cores&rdquo; = $Processor.NumberOfCores
&ldquo;OS&rdquo; = $OpSystem.Caption
&ldquo;Version&rdquo;= $OpSystem.Version
&ldquo;Memory&rdquo; = $OpSystem.TotalVisibleMemorySize
}
}
`They are all more or less the same. When properly formatted they are all equally readable. Most of them use a hash table of some sort. Therefor there are some language hurdles that need to be cleared, so why bother, why does it matter?&hellip; simple performance, with every release the PowerShell team have refined Object creation and the new way is always just a little bit faster. I used measure-command to measure the execution times for the above examples and well as you can see while minute every subsequent technique is slightly faster.<br>
New-Object/Add-Member = 1128 Milliseconds<br>
Select-Object                    = 1114 Milliseconds<br>
New-Object &ldquo;“property      = 1107 Milliseconds<br>
PSCustomObject             = 1100 Milliseconds<br>
Again not a huge deal but given a large enough dataset every tick counts. There were a litany of other things that I saw this week that made my list. The good news is this is all nitpicky stuff which is awesome!   Keep it up, and for the rest of you voters out there lets ease up with the ones and twos these are awesome scripts.  They may not use the technique you&rsquo;d prefer but for the most part they&rsquo;re getting the job done.<br>
~Glenn</p>
]]></content:encoded></item><item><title>As Event 3 gets underway, here are some Event 2 stats…</title><link>https://powershell.org/articles/2013-05-09-as-event-3-gets-underway-here-are-some-event-2-stats/</link><guid>https://powershell.org/articles/2013-05-09-as-event-3-gets-underway-here-are-some-event-2-stats/</guid><pubDate>Thu, 09 May 2013 23:50:57 +0000</pubDate><description>&lt;p&gt;Event 3 will be open for entries in about ten minutes, but I thought I&amp;rsquo;d share some Event 2 information. Keep in mind that Event 2 is open for voting until the 14th, GMT.&lt;br&gt;
Our Beginner Track had 120 entries this time, while the Advanced had 124. That contrasts with 165 and 159 from Event 1 - a perfectly normal falloff that&amp;rsquo;s occurred during every edition of past Games. Folks get busy, maybe get discouraged, but we&amp;rsquo;re keeping right on the trendline.&lt;br&gt;
Voting is down&amp;hellip; that happens, too, as the thrill of event 1 falls off. We had 3,966 Beginner votes and 2,775 Advanced votes in Event 1; so far we&amp;rsquo;ve gotten 1,446 Beginner and 1,131 Advanced in Event 2. Of course, we still have almost a week of voting left to go in Event 2, and in Event 1 we took a lot of votes up to the last minute.&lt;br&gt;
The good news is that Event 2&amp;rsquo;s votes have, so far, included a much higher percentage of comments. Event 1 Beginner has about 55% comments, while Advanced had 58%. In Event 2, Beginner is tracking to 63%, while Advanced is at 59%. Good job, guys - those comments are a big help. As you know, we&amp;rsquo;ve also put up some general guidelines to help keep everyone on the same page with what the score levels mean, so hopefully that&amp;rsquo;s helping, too.&lt;br&gt;
Something&amp;rsquo;s sure helping. The average score in Event 1 Beginner was 2.5585, and Advanced 2.3870. Event 2 is up a notch, at 2.6957 and 2.6631. That&amp;rsquo;s a 5% jump in Beginner scores and over 11% jump in Advanced scores. I know, people are tough on the scoring. And in some cases, I&amp;rsquo;m seeing comments that indicate the comment author had some misunderstandings. That&amp;rsquo;s okay - it&amp;rsquo;s an opportunity for us all to learn together, especially after the Games complete and we can start diving into this mess of data.&lt;br&gt;
I hope you&amp;rsquo;re already to start on Event 3! Our fastest entry so far is just over 51 minutes, and I might be saving some special prizes for the overall fastest entry (don&amp;rsquo;t worry - I&amp;rsquo;m going to look at it to make sure it&amp;rsquo;s decent).&lt;br&gt;
May the Games be Ever in Your Fav&amp;hellip; ugh, sorry. Don&amp;rsquo;t know where that came from. Good luck!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Event 3 will be open for entries in about ten minutes, but I thought I&rsquo;d share some Event 2 information. Keep in mind that Event 2 is open for voting until the 14th, GMT.<br>
Our Beginner Track had 120 entries this time, while the Advanced had 124. That contrasts with 165 and 159 from Event 1 - a perfectly normal falloff that&rsquo;s occurred during every edition of past Games. Folks get busy, maybe get discouraged, but we&rsquo;re keeping right on the trendline.<br>
Voting is down&hellip; that happens, too, as the thrill of event 1 falls off. We had 3,966 Beginner votes and 2,775 Advanced votes in Event 1; so far we&rsquo;ve gotten 1,446 Beginner and 1,131 Advanced in Event 2. Of course, we still have almost a week of voting left to go in Event 2, and in Event 1 we took a lot of votes up to the last minute.<br>
The good news is that Event 2&rsquo;s votes have, so far, included a much higher percentage of comments. Event 1 Beginner has about 55% comments, while Advanced had 58%. In Event 2, Beginner is tracking to 63%, while Advanced is at 59%. Good job, guys - those comments are a big help. As you know, we&rsquo;ve also put up some general guidelines to help keep everyone on the same page with what the score levels mean, so hopefully that&rsquo;s helping, too.<br>
Something&rsquo;s sure helping. The average score in Event 1 Beginner was 2.5585, and Advanced 2.3870. Event 2 is up a notch, at 2.6957 and 2.6631. That&rsquo;s a 5% jump in Beginner scores and over 11% jump in Advanced scores. I know, people are tough on the scoring. And in some cases, I&rsquo;m seeing comments that indicate the comment author had some misunderstandings. That&rsquo;s okay - it&rsquo;s an opportunity for us all to learn together, especially after the Games complete and we can start diving into this mess of data.<br>
I hope you&rsquo;re already to start on Event 3! Our fastest entry so far is just over 51 minutes, and I might be saving some special prizes for the overall fastest entry (don&rsquo;t worry - I&rsquo;m going to look at it to make sure it&rsquo;s decent).<br>
May the Games be Ever in Your Fav&hellip; ugh, sorry. Don&rsquo;t know where that came from. Good luck!</p>
]]></content:encoded></item><item><title>Event 2: My notes…</title><link>https://powershell.org/articles/2013-05-09-event-2-my-notes/</link><guid>https://powershell.org/articles/2013-05-09-event-2-my-notes/</guid><pubDate>Thu, 09 May 2013 21:50:28 +0000</pubDate><description>&lt;p&gt;Today I finally had some time to look at all entries in both categories. What I liked, and what I did not like about them? You can find answers, as previously, either in &lt;a href="http://powershellpl.net/2013/05/09/scripting-games-moje-notatki-2/"&gt;Polish&lt;/a&gt;, or in &lt;a href="http://becomelotr.wordpress.com/2013/05/09/event-2-my-notes/"&gt;English&lt;/a&gt;. I focused mainly on things I did not like, but I would anyway say that scripts are really good (overall) this year. Still: few poppies died. If you are responsible for it - remember: at the end of the day, it is you who is tossing away strength that PowerShell offers: Object Oriented Pipeline. 1* note is nothing in comparison with report, that will exists only as long as your &lt;strong&gt;host&lt;/strong&gt;, very same that you want to &lt;strong&gt;write&lt;/strong&gt; on so much&amp;hellip; 😉&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Today I finally had some time to look at all entries in both categories. What I liked, and what I did not like about them? You can find answers, as previously, either in<a href="http://powershellpl.net/2013/05/09/scripting-games-moje-notatki-2/">Polish</a>, or in<a href="http://becomelotr.wordpress.com/2013/05/09/event-2-my-notes/">English</a>. I focused mainly on things I did not like, but I would anyway say that scripts are really good (overall) this year. Still: few poppies died. If you are responsible for it - remember: at the end of the day, it is you who is tossing away strength that PowerShell offers: Object Oriented Pipeline. 1* note is nothing in comparison with report, that will exists only as long as your<strong>host</strong>, very same that you want to<strong>write</strong> on so much&hellip; 😉</p>
]]></content:encoded></item><item><title>Meet the Scripting Games Judges: Jan Egil Ring</title><link>https://powershell.org/articles/2013-05-09-meet-the-scripting-games-judges-jan-egil-ring/</link><guid>https://powershell.org/articles/2013-05-09-meet-the-scripting-games-judges-jan-egil-ring/</guid><pubDate>Thu, 09 May 2013 13:37:33 +0000</pubDate><description>&lt;p&gt;&lt;a href="http://twitter.com/janegilring"&gt;Jan Egil Ring&lt;/a&gt; is a multiple-year recipient of the Microsoft Most Valuable Professional Award for his contributions in the Windows PowerShell technical community.&lt;br&gt;
He has a strong passion for Windows PowerShell, and regularly writes articles on his &lt;a href="http://blog.powershell.no"&gt;blog&lt;/a&gt;. He occasionally also writes articles for others, such as the &lt;a href="http://www.powershellmagazine.com"&gt;PowerShell Magazine.&lt;/a&gt;&lt;br&gt;
As a judge in the Scripting Games, he will be writing articles on his blog reviewing both good and bad observations in the reviewed scripts. Clean formatting and avoidance of using aliases in scripts is among the things he will be paying attention to.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p><a href="http://twitter.com/janegilring">Jan Egil Ring</a> is a multiple-year recipient of the Microsoft Most Valuable Professional Award for his contributions in the Windows PowerShell technical community.<br>
He has a strong passion for Windows PowerShell, and regularly writes articles on his<a href="http://blog.powershell.no">blog</a>. He occasionally also writes articles for others, such as the<a href="http://www.powershellmagazine.com">PowerShell Magazine.</a><br>
As a judge in the Scripting Games, he will be writing articles on his blog reviewing both good and bad observations in the reviewed scripts. Clean formatting and avoidance of using aliases in scripts is among the things he will be paying attention to.</p>
]]></content:encoded></item><item><title>Scripting Games 2013: Event 2 "˜Favorite"™ and "˜Not So Favorite"™</title><link>https://powershell.org/articles/2013-05-08-scripting-games-2013-event-2-favorite-and-not-so-favorite/</link><guid>https://powershell.org/articles/2013-05-08-scripting-games-2013-event-2-favorite-and-not-so-favorite/</guid><pubDate>Thu, 09 May 2013 03:27:44 +0000</pubDate><description>&lt;p&gt;Event 2 is in the books and with that, it is time to take a look at all of the scripts submitted and make the difficult decisions as to which ones I liked and which ones I didn&amp;rsquo;t quite like.  Just because a script landed on my &amp;ldquo;˜Not so Favorite&amp;rdquo;™ list doesn&amp;rsquo;t mean it was terrible. It was just that I felt that there were some things here and there that could have been looked at a little differently. In fact, the amount of submissions that were great really made my decisions much for difficult. Everyone has really shown just how much knowledge is out there and how there are many different approaches to a single problem!&lt;br&gt;
Check out my picks &lt;a href="http://learn-powershell.net/2013/05/08/scripting-games-2013-event-2-favorite-and-not-so-favorite/"&gt;here&lt;/a&gt;.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Event 2 is in the books and with that, it is time to take a look at all of the scripts submitted and make the difficult decisions as to which ones I liked and which ones I didn&rsquo;t quite like.  Just because a script landed on my &ldquo;˜Not so Favorite&rdquo;™ list doesn&rsquo;t mean it was terrible. It was just that I felt that there were some things here and there that could have been looked at a little differently. In fact, the amount of submissions that were great really made my decisions much for difficult. Everyone has really shown just how much knowledge is out there and how there are many different approaches to a single problem!<br>
Check out my picks<a href="http://learn-powershell.net/2013/05/08/scripting-games-2013-event-2-favorite-and-not-so-favorite/">here</a>.</p>
]]></content:encoded></item><item><title>Event 2 Smart-Aleck</title><link>https://powershell.org/articles/2013-05-08-event-2-smart-aleck/</link><guid>https://powershell.org/articles/2013-05-08-event-2-smart-aleck/</guid><pubDate>Wed, 08 May 2013 21:08:11 +0000</pubDate><description>&lt;p&gt;Very funny.&lt;a href="https://powershell.org/wp-content/uploads/2013/05/FirefoxScreenSnapz001.jpg"&gt;
&lt;/a&gt;&lt;br&gt;
&lt;a href="https://powershell.org/wp-content/uploads/2013/05/FirefoxScreenSnapz001.jpg"&gt;&lt;img src="https://powershell.org/wp-content/uploads/2013/05/FirefoxScreenSnapz001.jpg" alt="FirefoxScreenSnapz001"&gt;&lt;/a&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Very funny.<a href="https://powershell.org/wp-content/uploads/2013/05/FirefoxScreenSnapz001.jpg"/><br><a href="https://powershell.org/wp-content/uploads/2013/05/FirefoxScreenSnapz001.jpg"><img src="https://powershell.org/wp-content/uploads/2013/05/FirefoxScreenSnapz001.jpg" alt="FirefoxScreenSnapz001"/></p>
]]></content:encoded></item><item><title>More Judges' Notes on Event 2</title><link>https://powershell.org/articles/2013-05-08-more-judges-notes-on-event-2/</link><guid>https://powershell.org/articles/2013-05-08-more-judges-notes-on-event-2/</guid><pubDate>Wed, 08 May 2013 19:42:02 +0000</pubDate><description>&lt;p&gt;Tobias Weltner: &lt;a href="http://www.powertheshell.com/scripting-games-task-2-commentary/"&gt;http://www.powertheshell.com/scripting-games-task-2-commentary/&lt;/a&gt;&lt;br&gt;
Jan Egil Ring: &lt;a href="http://blog.powershell.no/2013/05/08/2013-scripting-games-learning-points-from-event-2/"&gt;http://blog.powershell.no/2013/05/08/2013-scripting-games-learning-points-from-event-2/&lt;/a&gt;&lt;br&gt;
Voting for Event 2 is going strong, and you&amp;rsquo;ve got several more days in which to vote and (most importantly) add comments. Hopefully, you&amp;rsquo;re also considering the judges&amp;rsquo; notes and adjusting your approach for each event.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Tobias Weltner:<a href="http://www.powertheshell.com/scripting-games-task-2-commentary/">http://www.powertheshell.com/scripting-games-task-2-commentary/</a><br>
Jan Egil Ring:<a href="http://blog.powershell.no/2013/05/08/2013-scripting-games-learning-points-from-event-2/">http://blog.powershell.no/2013/05/08/2013-scripting-games-learning-points-from-event-2/</a><br>
Voting for Event 2 is going strong, and you&rsquo;ve got several more days in which to vote and (most importantly) add comments. Hopefully, you&rsquo;re also considering the judges&rsquo; notes and adjusting your approach for each event.</p>
]]></content:encoded></item><item><title>Notes on Beginner Event 2</title><link>https://powershell.org/articles/2013-05-08-notes-on-beginner-event-2/</link><guid>https://powershell.org/articles/2013-05-08-notes-on-beginner-event-2/</guid><pubDate>Wed, 08 May 2013 15:29:51 +0000</pubDate><description>&lt;p&gt; First of all, congratulations! It looks to me like a lot of learning is going on; the 2nd event entries look really good to me. I especially liked the way a number of you built up a one-liner by starting with a_ Get-WmiObject Win32_ComputerSystem -ComputerName (Get-Content file.txt)_ and piping it into &lt;em&gt;Select-Object&lt;/em&gt; to generate the data. However, there were a couple of areas within the Select block that make me think that some more discussion of what $_ means in a pipeline would be helpful.&lt;br&gt;
Within the Select block, it is necessary to make a call to &lt;em&gt;Get-WmiObject Win32_OperatingSystem&lt;/em&gt; to get come additional information. It looks like everybody got the format correct: &lt;em&gt;@{Name=&amp;lsquo;OS&amp;rsquo;;Expression={Get-WmiObject}}&lt;/em&gt; where folks got into trouble was in specifying the ComputerName property. Some didn&amp;rsquo;t even include it, meaning that the OS value would be taken from the local computer and not the remote one. But, more often than not, the code contained a plain $_ : &lt;em&gt;@{Name=&amp;lsquo;OS&amp;rsquo;;Expression={(Get-WmiObject Win32_OperatingSystem -ComputerName $&lt;/em&gt;).Caption}}&lt;em&gt;. So, what&amp;rsquo;s wrong with this? The problem is the value of $&lt;/em&gt; at this point in the pipeline.&lt;br&gt;
Let&amp;rsquo;s try an experiment to show what I mean. Try this:&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p> First of all, congratulations! It looks to me like a lot of learning is going on; the 2nd event entries look really good to me. I especially liked the way a number of you built up a one-liner by starting with a_ Get-WmiObject Win32_ComputerSystem -ComputerName (Get-Content file.txt)_ and piping it into<em>Select-Object</em> to generate the data. However, there were a couple of areas within the Select block that make me think that some more discussion of what $_ means in a pipeline would be helpful.<br>
Within the Select block, it is necessary to make a call to<em>Get-WmiObject Win32_OperatingSystem</em> to get come additional information. It looks like everybody got the format correct:<em>@{Name=&lsquo;OS&rsquo;;Expression={Get-WmiObject}}</em> where folks got into trouble was in specifying the ComputerName property. Some didn&rsquo;t even include it, meaning that the OS value would be taken from the local computer and not the remote one. But, more often than not, the code contained a plain $_ :<em>@{Name=&lsquo;OS&rsquo;;Expression={(Get-WmiObject Win32_OperatingSystem -ComputerName $</em>).Caption}}<em>. So, what&rsquo;s wrong with this? The problem is the value of $</em> at this point in the pipeline.<br>
Let&rsquo;s try an experiment to show what I mean. Try this:</p><p><code>Get-WmiObject Win32_ComputerSystem | Select-Object @{Name='OS';Expression={Get-WmiObject Win32_OperatingSystem -ComputerName $_}}</code>What does it return? Only the label &ldquo;OS&rdquo; with no data and no error message. Why? To find out, lets change the code a little and see.</p><p><code>Get-WmiObject Win32_ComputerSystem | foreach {Get-WmiObject Win32_OperatingSystem -ComputerName $_}</code>This time, we do get an error message:</p><p><code>Get-WmiObject : Invalid parameter At line:1 char:47 + Get-WmiObject Win32_ComputerSystem | foreach {Get-WmiObject Win32_OperatingSyste ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand</code> &ldquo;Invalid Parameter&rdquo; means that $_ isn&rsquo;t a computer name. What is it? It&rsquo;s actually the entire Win32_ComputerSystem object. What you need to do is to select one of the object properties that contains the system&rsquo;s name ($<em>.__SERVER, $</em>.Name, or $<em>.PSComputerName).<br>
Hopefully, this wasn&rsquo;t too long or complex a description. The point is be careful in your pipelines that you know exactly what $</em> means at each step.</p><blockquote/>]]></content:encoded></item><item><title>Tips on Implementing Pipeline Support</title><link>https://powershell.org/articles/2013-05-07-tips-on-implementing-pipeline-support/</link><guid>https://powershell.org/articles/2013-05-07-tips-on-implementing-pipeline-support/</guid><pubDate>Wed, 08 May 2013 03:16:27 +0000</pubDate><description>&lt;p&gt;While reviewing Event 1 (and now Event 2) I&amp;rsquo;ve seen some scripts that don&amp;rsquo;t quite have the correct pipeline support and others that do a great job with it. Whether it is an unneeded Begin or End statement, or throwing everything into a Process block and not quite getting the expected output or even having a Process block when ValueFromPipeline/ValueFromPipelineByPropertyName is not even enabled. Before I start working through my notes for Event 2, I wanted to get this post out of the way. I hope that what I put together here will help those out who are working to implement pipeline support in their code as well as providing a method of troubleshooting the parameter binding using Trace-Command. The blog post is available &lt;a href="http://learn-powershell.net/2013/05/07/tips-on-implementing-pipeline-support/"&gt;here to view&lt;/a&gt;.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>While reviewing Event 1 (and now Event 2) I&rsquo;ve seen some scripts that don&rsquo;t quite have the correct pipeline support and others that do a great job with it. Whether it is an unneeded Begin or End statement, or throwing everything into a Process block and not quite getting the expected output or even having a Process block when ValueFromPipeline/ValueFromPipelineByPropertyName is not even enabled. Before I start working through my notes for Event 2, I wanted to get this post out of the way. I hope that what I put together here will help those out who are working to implement pipeline support in their code as well as providing a method of troubleshooting the parameter binding using Trace-Command. The blog post is available<a href="http://learn-powershell.net/2013/05/07/tips-on-implementing-pipeline-support/">here to view</a>.</p>
]]></content:encoded></item><item><title>PhillyPoSH 05/02/2013 meeting summary and presentation materials</title><link>https://powershell.org/articles/2013-05-07-phillyposh-05022013-meeting-summary-and-presentation-materials/</link><guid>https://powershell.org/articles/2013-05-07-phillyposh-05022013-meeting-summary-and-presentation-materials/</guid><pubDate>Wed, 08 May 2013 02:56:14 +0000</pubDate><description>&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://jeffwouters.nl/"&gt;Jeff Wouters&lt;/a&gt; gave an excellent &lt;a href="https://powershell.org/wp-content/uploads/2013/05/PhillyPosh_2013-05-02_Presentation_JeffWouters.zip"&gt;presentation &lt;/a&gt;via Lync on:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; Avoiding the pipeline
-
Improving your learning curve
-
Improving your teaching curve
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://technet.microsoft.com/en-us/library/hh529924%28v=exchg.141%29.aspx#BKMK_MultiValueCustom"&gt;John Mello&lt;/a&gt; gave a &lt;a href="https://powershell.org/wp-content/uploads/2013/05/PhillyPosh_2013-05-02_ScriptClub.zip"&gt;presentation and demo of script &lt;/a&gt;that uses &lt;a href="http://technet.microsoft.com/en-us/library/hh529924%28v=exchg.141%29.aspx#BKMK_MultiValueCustom"&gt;Exchange multi-valued custom attributes&lt;/a&gt; to store information on when to remove users from a security group after a specified amount of days.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Standalone meeting material links&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[PhillyPosh_2013-05-02_ScriptClub](https://powershell.org/wp-content/uploads/2013/05/PhillyPosh_2013-05-02_ScriptClub.zip)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://powershell.org/wp-content/uploads/2013/05/PhillyPosh_2013-05-02_Presentation_JeffWouters.zip"&gt;PhillyPosh_2013-05-02_Presentation_JeffWouters&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description><content:encoded>&lt;![CDATA[<ul><li><p><a href="http://jeffwouters.nl/">Jeff Wouters</a> gave an excellent<a href="https://powershell.org/wp-content/uploads/2013/05/PhillyPosh_2013-05-02_Presentation_JeffWouters.zip">presentation</a>via Lync on:</p><pre><code> Avoiding the pipeline
-
Improving your learning curve
-
Improving your teaching curve</code></pre><ul><li><p><a href="http://technet.microsoft.com/en-us/library/hh529924%28v=exchg.141%29.aspx#BKMK_MultiValueCustom">John Mello</a> gave a<a href="https://powershell.org/wp-content/uploads/2013/05/PhillyPosh_2013-05-02_ScriptClub.zip">presentation and demo of script</a>that uses<a href="http://technet.microsoft.com/en-us/library/hh529924%28v=exchg.141%29.aspx#BKMK_MultiValueCustom">Exchange multi-valued custom attributes</a> to store information on when to remove users from a security group after a specified amount of days.</p></li><li><p>Standalone meeting material links</p><pre><code>[PhillyPosh_2013-05-02_ScriptClub](https://powershell.org/wp-content/uploads/2013/05/PhillyPosh_2013-05-02_ScriptClub.zip)</code></pre><ul><li><a href="https://powershell.org/wp-content/uploads/2013/05/PhillyPosh_2013-05-02_Presentation_JeffWouters.zip">PhillyPosh_2013-05-02_Presentation_JeffWouters</a></li></ul></li></ul></li></ul>
]]></content:encoded></item><item><title>Don's Event 2 Notes</title><link>https://powershell.org/articles/2013-05-07-dons-event-2-notes/</link><guid>https://powershell.org/articles/2013-05-07-dons-event-2-notes/</guid><pubDate>Tue, 07 May 2013 23:02:02 +0000</pubDate><description>&lt;p&gt;I thought I&amp;rsquo;d mentioned this last time (tap tap, this thing on?), but maybe not: don&amp;rsquo;t format the output of your functions. The minute a function includes Format-*, you&amp;rsquo;ve trapped me into on-screen display, a text file or piece of paper modeled after the on-screen display, or not a lot of other choices. If I want formatting, I&amp;rsquo;ll pipe your function to my own Format-* command of choice. But if I want CSV, or HTML, or XML, I&amp;rsquo;d like that option. Thanks.&lt;br&gt;
This is not a favorite technique of mine:&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I thought I&rsquo;d mentioned this last time (tap tap, this thing on?), but maybe not: don&rsquo;t format the output of your functions. The minute a function includes Format-*, you&rsquo;ve trapped me into on-screen display, a text file or piece of paper modeled after the on-screen display, or not a lot of other choices. If I want formatting, I&rsquo;ll pipe your function to my own Format-* command of choice. But if I want CSV, or HTML, or XML, I&rsquo;d like that option. Thanks.<br>
This is not a favorite technique of mine:</p><p><code>$ServerInfo = "" | Select-Object Name, SerialNumber, OS, Model, CPU, CPUCount, Memory, GBMemory $ServerInfo.Name = $Server.ToUpper() $ServerInfo.SerialNumber =(Get-WmiObject -Class Win32_BIOS -ComputerName $Server -Credential $Credential).SerialNumber</code>That said, it&rsquo;s not &ldquo;wrong&rdquo; so I only knock of like 1/10th of a point. For me, this technique is a bit of a hack, and it doesn&rsquo;t parse well visually. You&rsquo;re relying on Select-Object accepting non-existent property names and turning them into blank properties for you. It&rsquo;s&hellip; well, it&rsquo;s weird, and frankly this behavior - while convenient in this instance - causes more harm than good. Ever typo a property name on Select, and get a blank column as a result? Yeah, that. I wish Select didn&rsquo;t work this way, and so as a result I&rsquo;m not a fan of this technique.<br>
-&ndash;</p><p><code>if ($ServerInfo.CPU -is [array]) { $ServerInfo.CPU = $ServerInfo.CPU[0] }</code>Nice thinking, muchacho. You don&rsquo;t know if you&rsquo;ve got more than one object, so you check. I&rsquo;ll note, however, that this could have been done more concisely when you got the property:</p><p><code>$ServerInfo.CPU = (Get-WmiObject -Class Win32_Processor -ComputerName $Server -Credential $Credential).Name</code>Add a<strong>Select -First 1</strong> to the end of that and you&rsquo;d be guaranteed of only having one.<br>
-&ndash;</p><p><code>$ServerInfo.SerialNumber =(Get-WmiObject -Class Win32_BIOS -ComputerName $Server -Credential $Credential).SerialNumber $ServerInfo.OS = (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Server -Credential $Credential).Caption $ServerInfo.Model = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Server -Credential $Credential).Model $ServerInfo.CPU = (Get-WmiObject -Class Win32_Processor -ComputerName $Server -Credential $Credential).Name $ServerInfo.CPUCount = (Get-WmiObject -Class Win32_Processor -ComputerName $Server -Credential $Credential).count $ServerInfo.Memory = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Server -Credential $Credential).TotalPhysicalMemory</code>Saw a lotta this. I&rsquo;m kinda picking examples from one script, but this happened a lot. You&rsquo;re executing 6 queries. You needed 3. Double the effort, double the time. Bad call. Query it once, save it in a variable, extract what you need from that.<br>
-&ndash;</p><p><code>param( [Parameter( Position=0, Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true )] [string[]]$computers )</code>This hurts a little. Look at every native PowerShell command that accepts computer names, and it does so on a -ComputerName parameter. So why pick -computers for your function and be all nonstandard? Stay consistent.<br>
-&ndash;</p><p><code>$s = New-Object System.Object $os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer $s | Add-Member -Type NoteProperty -Name "Server Name" -Value $os.CSName $s | Add-Member -Type NoteProperty -Name "OS Version" -Value $os.Caption $cs = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer $mem = [string]([Math]::Round(($cs.TotalPhysicalMemory / 1MB),2)) + " MB" $s | Add-Member -Type NoteProperty -Name "PhysicalMem" -Value $mem $s | Add-Member -Type NoteProperty -Name "# CPUs" -Value $cs.NumberOfProcessors $cpu = Get-WmiObject -Class Win32_Processor -ComputerName $computer</code>Ahh, that&rsquo;s better. One query per class, then extract what you want from a variable. You can be a bit more concise using a hashtable, but I&rsquo;m jiggy with this technique.<br>
I said &ldquo;jiggy.&rdquo;<br>
-&ndash;<br>
I want to point out that Dr. Scripto was optional about the &ldquo;number of cores in each socket&rdquo; thing. He said, &ldquo;if you can do it.&rdquo; You can&rsquo;t. Not readily; XP doesn&rsquo;t expose that information (having existed before the advent of cores, um, time to upgrade okaythanksbuhbye) so you couldn&rsquo;t get it consistently for all of the operating systems you were asked for. Sometimes, the test is about seeing when you know to quit, not seeing if you can piledrive your way into a half-answer.<br>
-&ndash;<br>
You know you totally get downvoted if you don&rsquo;t include comment-based help with functions, right? Advanced track only. Just saying.-&ndash;</p><p><code>"Server name: " + $Info.Caption "OS: " + $Info2.Caption + $Info2.CSDVersion "Processor sockets: " + $Info.NumberOfProcessors "Processor cores: " + $Info.NumberOfLogicalProcessors "Physical memory: " + [Math]::Round(($Info.TotalPhysicalMemory/1GB),2) + "GB"</code>Yeah. Outputting formatted text instead of objects. I know. I cried for the dead puppies, and then drank. I drank<em>vodka.</em> I hate vodka, but the puppies. There is seriously a better way to output - outputting text prevents PowerShell from doing ANYTHING USEFUL with your output.<a href="http://scriptinggames.org/entrylist.php?entryid=519">See how this guy did it</a>? Do that. I&rsquo;m not a huge ordered hashtable fan, but that&rsquo;s just me. I don&rsquo;t hate them as much as vodka. Or text output.<br>
-&ndash;<br><a href="http://scriptinggames.org/entrylist.php?entryid=552">This one is trending well</a>. I get it. It&rsquo;s beautiful. I think I wrote a book about this. My ONLY SINGLE NITPICK is that it&rsquo;s maybe a wee bit overwrought. I think it&rsquo;s because of the whole try CIM, then try DCOM, thing. He probably had to do it this way. I wish the new CIM cmdlets didn&rsquo;t require an explicit session to do DCOM. I think that&rsquo;s a big fail, because it forces you to write functions like this. Meh. I should write a proxy function for this. Anyway.<br>
-&ndash;</p><p><code>Write-Verbose -Message 'Creating runspace pool' $rp = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspacePool(1, $ThrottleLimit, $iss, $Host) $rp.Open()</code>I have no idea what to do with this.<a href="http://scriptinggames.org/entrylist.php?entryid=482">Here&rsquo;s the whole thing</a>. This person is likely a LOT smarter than me. Certainly WAY more patient. I&rsquo;m not sure Dr. Scripto anticipated a 317-line solution. I think he&rsquo;s rolled his own multithreading here. Just&hellip; wow. It&rsquo;s definitely overkill, by an order of magnitude, but props, man.<br>
Someone can explain it to me sometime after the vodka wears off, yeah?<br>
-&ndash;<br>
People are<a href="http://scriptinggames.org/entrylist.php?entryid=513">hating on this one</a>. They&rsquo;re wrong. It&rsquo;s a good entry. Let me tell you something, stop giving a score of &ldquo;2&rdquo; because someone did something<em>extra</em> like add logging. If it works, they went above and beyond. Do you not reward people for going above and beyond in your organization? No? Well, you should.</p>
]]></content:encoded></item><item><title>Are you getting unfair comments in the Games?</title><link>https://powershell.org/articles/2013-05-07-are-you-geting-unfair-comments-in-the-games/</link><guid>https://powershell.org/articles/2013-05-07-are-you-geting-unfair-comments-in-the-games/</guid><pubDate>Tue, 07 May 2013 17:33:59 +0000</pubDate><description>&lt;p&gt;I continue to be amused by folks&amp;rsquo; reactions to the Games this year.&lt;br&gt;
There&amp;rsquo;s been some buzz on Twitter this morning from folks who feel some of their comments - and the corresponding low scores - aren&amp;rsquo;t warranted. In a couple of cases I&amp;rsquo;ve looked at, they&amp;rsquo;re right - their entries are being downrated for reasons that are actually not best practices; by following the best practices, these entries are getting lower scores.&lt;br&gt;
This reinforces a point I keep trying to make: The Games &lt;em&gt;&lt;strong&gt;aren&amp;rsquo;t about YOU. They&amp;rsquo;re about US.&lt;/strong&gt;&lt;/em&gt; ****&lt;br&gt;
Let me put it another way: if you&amp;rsquo;re getting comments from folks whose opinions are founded in a misunderstanding or misconception, that&amp;rsquo;s an opportunity to educate. Not to attack that commenter - which is why commenter names aren&amp;rsquo;t shown - but to educate the community in general. The community took the time to give you comments, and although some of them might be misguided, &lt;em&gt;you&lt;/em&gt; can take the time to offer a productive counterpoint and perhaps lay some misunderstandings to rest.&lt;br&gt;
That&amp;rsquo;s the point of the Games: to learn. Maybe not for &lt;strong&gt;you&lt;/strong&gt; to learn, but maybe for you to help &lt;strong&gt;someone else&lt;/strong&gt; learn. Or to put it another way, I haven&amp;rsquo;t received Microsoft&amp;rsquo;s MVP Award for ten years straight because I got a good &amp;ldquo;score&amp;rdquo; on something. I got it because I look for teachable moments and try to offer explanations. Being able to teach something shows that you &lt;em&gt;really&lt;/em&gt; know it.&lt;br&gt;
Think of your Games entries as a honeypot. If you can attract some folks who don&amp;rsquo;t quite get what you&amp;rsquo;re doing, then through the comments you&amp;rsquo;ll spot broad areas of educational opportunity, or what I call &amp;ldquo;teachable moments.&amp;rdquo; Seize on those and help bring the community as a whole to a higher level.&lt;br&gt;
Does that mean the educational opportunity has to come at the cost of you getting a lower score? Yup. Will that score in any other way impact your life? Nope. It&amp;rsquo;s not going on your permanent record. Human Resources will never know. It won&amp;rsquo;t affect your salary, or your ability to choose which movie you will see this weekend (Iron Man 3, BTW). Thicken up that skin a little - every vote isn&amp;rsquo;t a personal attack on you. Every &amp;ldquo;unqualified&amp;rdquo; comment is not a stain upon your honor.&lt;br&gt;
I really wish I could use some of the cooler interjections from &lt;em&gt;Spartacus&lt;/em&gt; here, but none of that stuff is suitable for a professional environment :(.&lt;br&gt;
In short: Cool yer jets. Take the opportunity to educate. Not on Twitter. Man, you guys with the tweets. You don&amp;rsquo;t have a blog, drop me an e-mail and I&amp;rsquo;ll give you authoring permissions right here on PowerShell.org. Help us, as a community, educate each other.&lt;br&gt;
And hey, remember not ALL of your comments are non-constructive. Learn from the ones you can, tune out the rest. Like watching CNN. Ever notice how, on a slow news day, the talk about Atlanta&amp;rsquo;s traffic? Exactly.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I continue to be amused by folks&rsquo; reactions to the Games this year.<br>
There&rsquo;s been some buzz on Twitter this morning from folks who feel some of their comments - and the corresponding low scores - aren&rsquo;t warranted. In a couple of cases I&rsquo;ve looked at, they&rsquo;re right - their entries are being downrated for reasons that are actually not best practices; by following the best practices, these entries are getting lower scores.<br>
This reinforces a point I keep trying to make: The Games<em><strong>aren&rsquo;t about YOU. They&rsquo;re about US.</strong></em> ****<br>
Let me put it another way: if you&rsquo;re getting comments from folks whose opinions are founded in a misunderstanding or misconception, that&rsquo;s an opportunity to educate. Not to attack that commenter - which is why commenter names aren&rsquo;t shown - but to educate the community in general. The community took the time to give you comments, and although some of them might be misguided,<em>you</em> can take the time to offer a productive counterpoint and perhaps lay some misunderstandings to rest.<br>
That&rsquo;s the point of the Games: to learn. Maybe not for<strong>you</strong> to learn, but maybe for you to help<strong>someone else</strong> learn. Or to put it another way, I haven&rsquo;t received Microsoft&rsquo;s MVP Award for ten years straight because I got a good &ldquo;score&rdquo; on something. I got it because I look for teachable moments and try to offer explanations. Being able to teach something shows that you<em>really</em> know it.<br>
Think of your Games entries as a honeypot. If you can attract some folks who don&rsquo;t quite get what you&rsquo;re doing, then through the comments you&rsquo;ll spot broad areas of educational opportunity, or what I call &ldquo;teachable moments.&rdquo; Seize on those and help bring the community as a whole to a higher level.<br>
Does that mean the educational opportunity has to come at the cost of you getting a lower score? Yup. Will that score in any other way impact your life? Nope. It&rsquo;s not going on your permanent record. Human Resources will never know. It won&rsquo;t affect your salary, or your ability to choose which movie you will see this weekend (Iron Man 3, BTW). Thicken up that skin a little - every vote isn&rsquo;t a personal attack on you. Every &ldquo;unqualified&rdquo; comment is not a stain upon your honor.<br>
I really wish I could use some of the cooler interjections from<em>Spartacus</em> here, but none of that stuff is suitable for a professional environment :(.<br>
In short: Cool yer jets. Take the opportunity to educate. Not on Twitter. Man, you guys with the tweets. You don&rsquo;t have a blog, drop me an e-mail and I&rsquo;ll give you authoring permissions right here on PowerShell.org. Help us, as a community, educate each other.<br>
And hey, remember not ALL of your comments are non-constructive. Learn from the ones you can, tune out the rest. Like watching CNN. Ever notice how, on a slow news day, the talk about Atlanta&rsquo;s traffic? Exactly.</p>
]]></content:encoded></item><item><title>Scripting Games Event 1 Winners</title><link>https://powershell.org/articles/2013-05-07-scripting-games-event-1-winners/</link><guid>https://powershell.org/articles/2013-05-07-scripting-games-event-1-winners/</guid><pubDate>Tue, 07 May 2013 16:11:57 +0000</pubDate><description>&lt;p&gt;We&amp;rsquo;re pleased to announce the winners for Event 1 of The Scripting Games 2013!&lt;br&gt;
Winners: You can log into &lt;a href="http://scriptinggames.org/"&gt;The Scripting Games Web site&lt;/a&gt; and go to your Profile page to see your prize. You will be given a prize redemption code and either a URL where you can redeem it, or an e-mail address of the prize provider (they will need the redemption code). All prizes must be claimed by the end of July 2013. I will list winners by username; if you used your e-mail address as your username, then a portion of that will be truncated for your privacy. Anyone can log in and check their Profile page to see if they&amp;rsquo;ve won a prize.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>We&rsquo;re pleased to announce the winners for Event 1 of The Scripting Games 2013!<br>
Winners: You can log into<a href="http://scriptinggames.org/">The Scripting Games Web site</a> and go to your Profile page to see your prize. You will be given a prize redemption code and either a URL where you can redeem it, or an e-mail address of the prize provider (they will need the redemption code). All prizes must be claimed by the end of July 2013. I will list winners by username; if you used your e-mail address as your username, then a portion of that will be truncated for your privacy. Anyone can log in and check their Profile page to see if they&rsquo;ve won a prize.</p><ul><li><p>Event 1 Beginner First Place (free ebook from Manning): taygibb</p></li><li><p>Event 1 Beginner Second Place (free video training from Interface Technical Training): alvaroBT</p></li><li><p>Event 1 Beginner Third Place (free year of Phoneominal service from Start-Automating): Novice</p></li><li><p>Event 1 Advanced First Place (free ebook from Manning): mikefrobbins</p></li><li><p>Event 1 Advanced Second Place (free video training from Interface Technical Training): Toni</p></li><li><p>Event 1 Advanced Third Place (free year of Phoneominal service from Start-Automating): lido</p></li><li><p>Event 1 Beginner Top CrowdScore (free ebook from Manning): taygibb</p></li><li><p>Event 1 Advanced Top CrowdScore (free ebook from Manning): mikefrobbins</p></li><li><p>CrowdScore Voter (free month of video training from Interface Technical Training): kirkaldrin</p></li><li><p>CrowdScore Voter (free month of video training from Interface Technical Training): KmTatar</p></li><li><p>CrowdScore Voter (free ebook from Manning): Klaus_Schulte</p></li><li><p>CrowdScore Voter (free ebook from Manning): Daniel</p></li><li><p>CrowdScore Voter ($50 Gift Certificate from SAPIEN Technologies): theotherkidd@__.com</p></li></ul><p>Congratulations to all of our winners! Note that our top three prizes in each category were awarded by our Mighty Panel of Celebrity Judges. Each judge nominated a first, second, and third place winner from the entries that our expert commentators identified as &ldquo;best.&rdquo; Those nominations were compiled, and in the event of a tie the earliest entry was deemed winner (that didn&rsquo;t happen, actually). I&rsquo;m mildly surprised that our community voting identified the same top scripters in each track - the 1st, 2nd, and 3rd-place award process didn&rsquo;t factor in the CrowdScore at all.</p>
]]></content:encoded></item><item><title>PowerShell Summit Videos</title><link>https://powershell.org/articles/2013-05-07-powershell-summit-videos/</link><guid>https://powershell.org/articles/2013-05-07-powershell-summit-videos/</guid><pubDate>Tue, 07 May 2013 15:52:59 +0000</pubDate><description>&lt;p&gt;Aaron Hoover, one of our Summit attendees, was kind enough to record via webcam the sessions he attended - and he&amp;rsquo;s posted about 13 hours of video on YouTube for your viewing pleasure.&lt;br&gt;
What I&amp;rsquo;d like to know from you, if you don&amp;rsquo;t mind dropping a comment below, is what you think of these. If we offered this KIND of recording in the future, would it be helpful? This is something we can do easily and is affordable from a technical perspective; there&amp;rsquo;s obviously a production quality compromise. We can do more&amp;hellip; but it costs more, and someone&amp;rsquo;s going to have to pay for it. So&amp;hellip; where do you sit on this kind of recording?&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Aaron Hoover, one of our Summit attendees, was kind enough to record via webcam the sessions he attended - and he&rsquo;s posted about 13 hours of video on YouTube for your viewing pleasure.<br>
What I&rsquo;d like to know from you, if you don&rsquo;t mind dropping a comment below, is what you think of these. If we offered this KIND of recording in the future, would it be helpful? This is something we can do easily and is affordable from a technical perspective; there&rsquo;s obviously a production quality compromise. We can do more&hellip; but it costs more, and someone&rsquo;s going to have to pay for it. So&hellip; where do you sit on this kind of recording?</p><ul><li><a href="http://youtu.be/0NeEU3FHp8I">http://youtu.be/0NeEU3FHp8I</a> Device Management With PowerShell - Ricardo Mendes - PowerShell Summit 2013</li><li><a href="http://youtu.be/XsnE_OQGvdo">http://youtu.be/XsnE_OQGvdo</a> Creating a Complex and Reusable HTML Reporting Structure - Alan Renouf - PowerShell Summit 2013</li><li><a href="http://youtu.be/iV6cYsQDL0Y">http://youtu.be/iV6cYsQDL0Y</a> How Secure Can You Be - Jeff Hicks PowerShell Summit 2013</li><li><a href="http://youtu.be/qSE06GkQWV4">http://youtu.be/qSE06GkQWV4</a> Standards Based Hardware Management - Steve Lee - PowerShell Summit 2013</li><li><a href="http://youtu.be/7C53pawPw3Y">http://youtu.be/7C53pawPw3Y</a> Workshop - Automating for DevOps - Kenneth Hansen and Hemant Mahawar - PowerShell Summit 2013</li><li><a href="http://youtu.be/KFA-zSojxqw">http://youtu.be/KFA-zSojxqw</a> CIM Sessions - Richard Siddaway - PowerShell Summit 2013</li><li><a href="http://youtu.be/EloMKpvfES8">http://youtu.be/EloMKpvfES8</a> PowerShell Web Access - Richard Siddaway - PowerShell Summit 2013</li><li><a href="http://youtu.be/3deY6e6Npzo">http://youtu.be/3deY6e6Npzo</a> Sapien PowerShell Products - David Corrales - PowerShell Summit 2013</li><li><a href="http://youtu.be/xZtapxf1ytI">http://youtu.be/xZtapxf1ytI</a> What I learned Judging 5000 Scripts - Ed Wilson - PowerShell Summit 2013</li><li><a href="http://youtu.be/Ahvs1rGPk1s">http://youtu.be/Ahvs1rGPk1s</a> PowerShell Events - Richard Siddaway - PowerShell Summit 2013</li><li><a href="http://youtu.be/U_niW85TtJE">http://youtu.be/U_niW85TtJE</a> Write Modules, Not Scripts - Ed Wilson - PowerShell Summit 2013</li><li><a href="http://youtu.be/Y8IbadEHoPg">http://youtu.be/Y8IbadEHoPg</a> PoshMon - PowerShell Does Performance Counters - Ed Wilson - PowerShell Summit 2013</li><li><a href="http://youtu.be/1XuB71tLNvg">http://youtu.be/1XuB71tLNvg</a> Configuring Your PowerShell Workflow Environment - Aleksandar Nikolic - PowerShell Summit 2013</li><li><a href="http://youtu.be/msHGx-mxWJA">http://youtu.be/msHGx-mxWJA</a> Practical PowerShell Integration from Bare Metal to the Cloud - Alan Renouf - PowerShell Summit 2013</li><li><a href="http://youtu.be/eAZ-agh182g">http://youtu.be/eAZ-agh182g</a> Source Control for IT Pros - Andy Schneider - PowerShell Summit 2013</li><li><a href="http://youtu.be/pL_Ry5LzX3w">http://youtu.be/pL_Ry5LzX3w</a> Creating HTML Reports with Style - Jeff Hicks - PowerShell Summit 2013</li><li><a href="http://youtu.be/-ERyfmOmyoI">http://youtu.be/-ERyfmOmyoI</a> Remoting Configuration Deep Dive - Don Jones - PowerShell Summit 2013</li><li><a href="http://youtu.be/jMVBN5V0G4Y">http://youtu.be/jMVBN5V0G4Y</a> Advanced Network Scripting with PowerShell - Lee Holmes - PowerShell Summit 2013</li><li><a href="http://youtu.be/GXkLtEOM-DM">http://youtu.be/GXkLtEOM-DM</a> Build Your Demo Environment with Windows PowerShell - Aleksandar Nikolic - PowerShell Summit 2013</li></ul>
]]></content:encoded></item><item><title>Event 2: My way…</title><link>https://powershell.org/articles/2013-05-06-event-2-my-way/</link><guid>https://powershell.org/articles/2013-05-06-event-2-my-way/</guid><pubDate>Tue, 07 May 2013 04:26:03 +0000</pubDate><description>&lt;p&gt;I haven&amp;rsquo;t received any negative feedback on idea to blog about &amp;ldquo;&lt;em&gt;how would I do it&lt;/em&gt;&amp;rdquo; (what you think about my approach is different topic) so I decided to continue. Again: because I don&amp;rsquo;t want to be influenced by your ideas and make my task as close to your work as possible I post it early, before I see any of cool techniques I haven&amp;rsquo;t thought of and you did, so that I can regret it later. &lt;a href="http://becomelotr.wordpress.com/2013/05/07/event-2-my-way/"&gt;You can find whole article on my blog&lt;/a&gt;. Enjoy, and please - if you see something silly, let me know. I really &lt;strong&gt;do&lt;/strong&gt; appreciate negative feedback!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I haven&rsquo;t received any negative feedback on idea to blog about &ldquo;<em>how would I do it</em>&rdquo; (what you think about my approach is different topic) so I decided to continue. Again: because I don&rsquo;t want to be influenced by your ideas and make my task as close to your work as possible I post it early, before I see any of cool techniques I haven&rsquo;t thought of and you did, so that I can regret it later.<a href="http://becomelotr.wordpress.com/2013/05/07/event-2-my-way/">You can find whole article on my blog</a>. Enjoy, and please - if you see something silly, let me know. I really<strong>do</strong> appreciate negative feedback!</p>
]]></content:encoded></item><item><title>Event 2 is final!</title><link>https://powershell.org/articles/2013-05-06-event-2-is-final/</link><guid>https://powershell.org/articles/2013-05-06-event-2-is-final/</guid><pubDate>Tue, 07 May 2013 00:23:43 +0000</pubDate><description>&lt;p&gt;Event 2 has closed for submissions and will open for voting later this evening. Good luck! And voters: remember that quality comments will vastly increase your chances of winning a prize!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Event 2 has closed for submissions and will open for voting later this evening. Good luck! And voters: remember that quality comments will vastly increase your chances of winning a prize!</p>
]]></content:encoded></item><item><title>A Helpful Message about HelpMessage</title><link>https://powershell.org/articles/2013-05-06-a-helpful-message-about-helpmessage/</link><guid>https://powershell.org/articles/2013-05-06-a-helpful-message-about-helpmessage/</guid><pubDate>Mon, 06 May 2013 23:39:21 +0000</pubDate><description>&lt;p&gt;The Scripting Games 2013 winners have not yet been announced, but for the 3rd year running, I&amp;rsquo;m in the lead for the &amp;ldquo;Learned Most from the Scripting Games&amp;rdquo; award. I&amp;rsquo;m making space for the prize on my bookshelf. Seriously, I play with PowerShell all the time and read lots of blogs, but nothing compares to looking at dozens of scripts and commands and seeing how people do things in the real world.&lt;br&gt;
One of the practices I&amp;rsquo;ve noticed is use of the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/system.management.automation.parameterattribute.helpmessage(v=vs.85).aspx"&gt;HelpMessage parameter attribute&lt;/a&gt; to document a parameter. It&amp;rsquo;s a real thing, but I didn&amp;rsquo;t know that anyone used it any more.&lt;br&gt;
Here&amp;rsquo;s my help message about HelpMessage:&lt;br&gt;
&lt;strong&gt;Don&amp;rsquo;t use it!&lt;/strong&gt; Users can&amp;rsquo;t see it. It does no harm, but it has no value. Danger lurks in writing a HelpMessage instead of writing help that users can see. Write help that Get-Help gets, that is, XML help or comment-based help.&lt;br&gt;
Here&amp;rsquo;s what I&amp;rsquo;m talking about. This code is valid. The language permits it. But it&amp;rsquo;s not useful. And I saw it in several of the advanced solutions.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>The Scripting Games 2013 winners have not yet been announced, but for the 3rd year running, I&rsquo;m in the lead for the &ldquo;Learned Most from the Scripting Games&rdquo; award. I&rsquo;m making space for the prize on my bookshelf. Seriously, I play with PowerShell all the time and read lots of blogs, but nothing compares to looking at dozens of scripts and commands and seeing how people do things in the real world.<br>
One of the practices I&rsquo;ve noticed is use of the<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/system.management.automation.parameterattribute.helpmessage(v=vs.85).aspx">HelpMessage parameter attribute</a> to document a parameter. It&rsquo;s a real thing, but I didn&rsquo;t know that anyone used it any more.<br>
Here&rsquo;s my help message about HelpMessage:<br><strong>Don&rsquo;t use it!</strong> Users can&rsquo;t see it. It does no harm, but it has no value. Danger lurks in writing a HelpMessage instead of writing help that users can see. Write help that Get-Help gets, that is, XML help or comment-based help.<br>
Here&rsquo;s what I&rsquo;m talking about. This code is valid. The language permits it. But it&rsquo;s not useful. And I saw it in several of the advanced solutions.</p><p><code>function Get-PowerShellLog { [CmdletBinding()] Param ( [Parameter(Mandatory=$true, HelpMessage="Your message goes here")] $InstanceID ) Get-Eventlog -LogName "Windows PowerShell" -InstanceId $InstanceID }</code>But Get-Help doesn&rsquo;t get the HelpMessage string.<br>
There are two ways for the user to see this help message. Here&rsquo;s one way. These commands get the value of the HelpMessage property of the parameter. I don&rsquo;t think people run commands like these very often, but I don&rsquo;t get out much.</p><p><code>#Windows PowerShell 3.0 C:\&gt; ((Get-Command Get-PowerShellLog).ParameterSets.Parameters | Where-Object Name -eq InstanceId).HelpMessage Your message goes here #Windows PowerShell 2.0 C:\&gt; ((Get-Command Get-PowerShellLog).ParameterSets | Foreach {$_.Parameters} | Where-Object {$_.Name -eq InstanceId).HelpMessage Your message goes here</code>Here&rsquo;s the other way. It works only on mandatory (required) parameters. When you omit a mandatory parameter, you get a message like this one:</p><p><code>PS C:\&gt; Get-PowerShellLog cmdlet Get-PowerShellLog at command pipeline position 1 Supply values for the following parameters: (Type !? for Help.) InstanceID:</code>And then you type &ldquo;!?&rdquo; to get the HelpMessage value.</p><p><code>InstanceID: !? Your message goes here</code>You&rsquo;ve never done that? Me neither!<br>
To get a sense of how often HelpMessage is used, I played Nate Silver with Kim&rsquo;s famous test server. My dear friend, Kim Ditto, is famous for many things &ndash; she&rsquo;s a fabulous person and a renowned Microsoft Certified Trainer &ndash; but, in addition, she set up and maintains a test server on which she&rsquo;s installed almost all of the Windows PowerShell modules from Microsoft. I could not live without Kim&rsquo;s test server.<br>
Here are the results. Out of 2468 commands with 8471 parameters, 8 have the HelpMessage attribute and none are mandatory, so the HelpMessage is<em>NEVER DISPLAYED</em> unless you go hunting for it.</p><p>`# How many commands?
PS C:&gt; Invoke-Command -Session $s {(Get-Command).Count}
2468</p><h1 id="how-many-parameters" class="ps-heading">How many parameters?<a class="ps-heading-anchor" href="#how-many-parameters" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><p>PS C:&gt; $a = Invoke-Command -Session $s `
{(Get-Command).ParameterSets.Parameters.Count}
8471</p><h1 id="how-many-parameters-have-helpmessage" class="ps-heading">How many parameters have HelpMessage?<a class="ps-heading-anchor" href="#how-many-parameters-have-helpmessage" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><p>PS C:&gt; Invoke-Command -Session $s `
{((Get-Command).ParameterSets.Parameters | where HelpMessage).Count}
8</p><h1 id="how-many-of-the-parameters-with-helpmessage-are-mandatory" class="ps-heading">How many of the parameters with HelpMessage are mandatory?<a class="ps-heading-anchor" href="#how-many-of-the-parameters-with-helpmessage-are-mandatory" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><p>PS C:&gt; Invoke-Command -Session $s<code>{((Get-Command).ParameterSets.Parameters | where HelpMessage -and isMandatory).Count} 0</code>If you want to be helpful, the correct way to provide help for a parameter in a script or function is this:</p><p><code>&lt;# .PARAMETER InstanceId Specifies the instance IDs of events in the event log. Get-PowerShellLog gets only logs with the specified ID. #&gt;</code>Or, this:</p><p>`[Parameter(Mandatory=$true, HelpMessage=&ldquo;Your message goes here&rdquo;)]</p><h1 id="specifies-the-instance-ids-of-events-in-the" class="ps-heading">Specifies the instance IDs of events in the<a class="ps-heading-anchor" href="#specifies-the-instance-ids-of-events-in-the" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><h1 id="event-log-get-powershelllog-gets-only-logs" class="ps-heading">event log. Get-PowerShellLog gets only logs<a class="ps-heading-anchor" href="#event-log-get-powershelllog-gets-only-logs" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><h1 id="with-the-specified-id" class="ps-heading">with the specified ID.<a class="ps-heading-anchor" href="#with-the-specified-id" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><p>$InstanceID
`Hope that&rsquo;s helpful.</p>
]]></content:encoded></item><item><title>Placing Comment-Based Help</title><link>https://powershell.org/articles/2013-05-03-placing-comment-based-help/</link><guid>https://powershell.org/articles/2013-05-03-placing-comment-based-help/</guid><pubDate>Fri, 03 May 2013 19:03:39 +0000</pubDate><description>&lt;p&gt;What an amazing event. I&amp;rsquo;m now reading through each of the Advanced entries in a vain attempt to whittle the entries down to a short list. It&amp;rsquo;s an incredibly difficult task, which is testament to your skill and diligence. We are so lucky to have so many competent scripters in the community.&lt;br&gt;
As I read through the comments on each script, I&amp;rsquo;ve noticed several that say:&lt;br&gt;
&amp;ldquo;Help should be nested under the function to work properly.&amp;rdquo;&lt;br&gt;
Au contraire! This is not true and I want to make sure that people who see this comment are not misled. The Windows PowerShell team designed comment-based help to be really flexible.&lt;br&gt;
As I explained in &lt;a href="http://go.microsoft.com/fwlink/?LinkID=144309"&gt;about_Comment_Based_Help&lt;/a&gt;, you can put comment-based help for a function in one of three positions:&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>What an amazing event. I&rsquo;m now reading through each of the Advanced entries in a vain attempt to whittle the entries down to a short list. It&rsquo;s an incredibly difficult task, which is testament to your skill and diligence. We are so lucky to have so many competent scripters in the community.<br>
As I read through the comments on each script, I&rsquo;ve noticed several that say:<br>
&ldquo;Help should be nested under the function to work properly.&rdquo;<br>
Au contraire! This is not true and I want to make sure that people who see this comment are not misled. The Windows PowerShell team designed comment-based help to be really flexible.<br>
As I explained in<a href="http://go.microsoft.com/fwlink/?LinkID=144309">about_Comment_Based_Help</a>, you can put comment-based help for a function in one of three positions:</p><ul><li>At the beginning of the function body</li><li>At the end of the function body</li><li>On the line before the Function keyword</li></ul><p>So, all of these work.</p><p><code>function Move-OldFiles { &lt;# .Synopsis Moves old log files to an archive directory. #&gt; Param ( [parameter(Mandatory=$true)] [String] $InputDirectory ) }</code>function Move-OldFiles
{
Param
(
[parameter(Mandatory=$true)]
[String]
$InputDirectory
)
#Script logic goes here
&lt;#
.Synopsis
Moves old log files to an archive directory.
#&gt;
}<code>&lt;# .Synopsis Moves old log files to an archive directory. #&gt; function Move-OldFiles { Param ( [parameter(Mandatory=$true)] [String] $InputDirectory ) #Script logic goes here }</code>If you place the comment-based help on the line before the Function keyword, make sure that there is, at most, one blank line between the end of the comment-based help and the line with the function keyword. To avoid this problem, I always make sure that there are no blank lines between the end of the comment-based help and the Function keyword.<br>
When reading the comments about your solutions, please remember that we are all volunteers. Everyone who takes the time to comment on your solution is trying to help, and should be appreciated, but not every comment is correct. Trust, but verify!</p>
]]></content:encoded></item><item><title>Scripting Games: What Should We Do With Comments?</title><link>https://powershell.org/articles/2013-05-03-scripting-games-what-should-we-do-with-comments/</link><guid>https://powershell.org/articles/2013-05-03-scripting-games-what-should-we-do-with-comments/</guid><pubDate>Fri, 03 May 2013 19:02:08 +0000</pubDate><description>&lt;p&gt;Right now, I&amp;rsquo;ve got the Scripting Games Web site built to only make comments visible to a entry&amp;rsquo;s author. Some of the comments have been a little snarky, and I don&amp;rsquo;t want to create an online argument forum.&lt;br&gt;
I&amp;rsquo;m curious what folks think we should do as a next step.&lt;br&gt;
I could, for example, make comments visible to everyone once voting has ended for an event (I don&amp;rsquo;t want to make comments visible while we&amp;rsquo;re still accepting comments, because it&amp;rsquo;ll run a big risk of creating a discussion, which isn&amp;rsquo;t the intent).&lt;br&gt;
We do have a plan to dump all the entries into static files for long-term reference; I could insert entries&amp;rsquo; comments at the end of each entry, in a PowerShell comment block.&lt;br&gt;
Or, we could just leave comments visible to the entry&amp;rsquo;s author. That provides a learning experience for the author, although not for the public, and only until we purge the database for the next event.&lt;br&gt;
Thoughts?&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Right now, I&rsquo;ve got the Scripting Games Web site built to only make comments visible to a entry&rsquo;s author. Some of the comments have been a little snarky, and I don&rsquo;t want to create an online argument forum.<br>
I&rsquo;m curious what folks think we should do as a next step.<br>
I could, for example, make comments visible to everyone once voting has ended for an event (I don&rsquo;t want to make comments visible while we&rsquo;re still accepting comments, because it&rsquo;ll run a big risk of creating a discussion, which isn&rsquo;t the intent).<br>
We do have a plan to dump all the entries into static files for long-term reference; I could insert entries&rsquo; comments at the end of each entry, in a PowerShell comment block.<br>
Or, we could just leave comments visible to the entry&rsquo;s author. That provides a learning experience for the author, although not for the public, and only until we purge the database for the next event.<br>
Thoughts?</p>
]]></content:encoded></item><item><title>Beginner Event Tips</title><link>https://powershell.org/articles/2013-05-03-beginner-event-tips/</link><guid>https://powershell.org/articles/2013-05-03-beginner-event-tips/</guid><pubDate>Fri, 03 May 2013 15:57:10 +0000</pubDate><description>&lt;p&gt;Folks, as we dive into Event 2, I want to offer some advice based on the &lt;em&gt;comments&lt;/em&gt; I saw for Event 1.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Don&amp;rsquo;t overthink the Beginner event. We&amp;rsquo;re not looking for a script or function - a one-liner, if possible. Don&amp;rsquo;t overdeliver.&lt;/li&gt;
&lt;li&gt;Avoid aliases and positional parameters - this is a practice outlined in the Competitor Guide.&lt;/li&gt;
&lt;li&gt;TEST YOUR CODE. You can&amp;rsquo;t modify it. Also, judges can&amp;rsquo;t see any comment you might leave when &amp;ldquo;voting&amp;rdquo; on your own entry, so you can&amp;rsquo;t use comments to mitigate an error. TEST. Submitting an entry is like pushing a script into production.&lt;/li&gt;
&lt;li&gt;If there&amp;rsquo;s a straightforward, native way to do something - do it. People seemed to down-vote a lot of entries in Event 1 for using Robocopy. Not that it&amp;rsquo;s wrong&amp;hellip; but the general community opinion seems to be, &amp;ldquo;use native commands when they exist and can solve the problem.&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Remember, these aren&amp;rsquo;t my guidelines - this is what I&amp;rsquo;m seeing in the comments that I&amp;rsquo;m reviewing, and wanted to pass them along as a sense of what the community seems to favor and disfavor.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Folks, as we dive into Event 2, I want to offer some advice based on the<em>comments</em> I saw for Event 1.</p><ul><li>Don&rsquo;t overthink the Beginner event. We&rsquo;re not looking for a script or function - a one-liner, if possible. Don&rsquo;t overdeliver.</li><li>Avoid aliases and positional parameters - this is a practice outlined in the Competitor Guide.</li><li>TEST YOUR CODE. You can&rsquo;t modify it. Also, judges can&rsquo;t see any comment you might leave when &ldquo;voting&rdquo; on your own entry, so you can&rsquo;t use comments to mitigate an error. TEST. Submitting an entry is like pushing a script into production.</li><li>If there&rsquo;s a straightforward, native way to do something - do it. People seemed to down-vote a lot of entries in Event 1 for using Robocopy. Not that it&rsquo;s wrong&hellip; but the general community opinion seems to be, &ldquo;use native commands when they exist and can solve the problem.&rdquo;</li></ul><p>Remember, these aren&rsquo;t my guidelines - this is what I&rsquo;m seeing in the comments that I&rsquo;m reviewing, and wanted to pass them along as a sense of what the community seems to favor and disfavor.</p>
]]></content:encoded></item><item><title>OK i'm impressed: Scripting Games Week 1</title><link>https://powershell.org/articles/2013-05-03-ok-im-impressed-scripting-games-week-1/</link><guid>https://powershell.org/articles/2013-05-03-ok-im-impressed-scripting-games-week-1/</guid><pubDate>Fri, 03 May 2013 14:44:21 +0000</pubDate><description>&lt;p&gt;Well guys, and gals another year has passed, and the annual scripting games are upon us again.  After a week of reviewing submissions for their technique and style I must say that I am truly impressed!  As a community the average ability seems to be growing by leaps and bounds.  That&amp;quot;™s not to say we&amp;quot;™re all Samurai just yet, but we&amp;quot;™re getting there!&lt;br&gt;
Before I go off and nit-pick I want to congratulate you all on a small mountain of really well written scripts.  Some of the things that the community was preaching 5 years ago are now just standard.  Stuff like comment your code, format for readability, and Parameters.  At this point I&amp;quot;™m convinced those who still aren&amp;rsquo;t conforming are simply non-conformist and well that&amp;quot;™s a lost cause.  For the rest of us great work and keep it up!&lt;br&gt;
**Where is the Help!&lt;br&gt;
**
What I 
didn&amp;rsquo;t
 see enough of in the advanced category is help.  Honestly if you&amp;quot;™re going to write a 200 line script fill out the help!  It&amp;quot;™s not that hard and it is THE difference between a good script and a great solution! It&amp;quot;™s also one of the fundamental differences between hacking and tool building, both are focused around automating a given problem set.  The hacker just gets it to work, the tool builder makes it usable by the masses.  If you haven&amp;quot;™t figured it out yet the real money is in tool building, I&amp;quot;™m just sayin!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Well guys, and gals another year has passed, and the annual scripting games are upon us again.  After a week of reviewing submissions for their technique and style I must say that I am truly impressed!  As a community the average ability seems to be growing by leaps and bounds.  That"™s not to say we"™re all Samurai just yet, but we"™re getting there!<br>
Before I go off and nit-pick I want to congratulate you all on a small mountain of really well written scripts.  Some of the things that the community was preaching 5 years ago are now just standard.  Stuff like comment your code, format for readability, and Parameters.  At this point I"™m convinced those who still aren&rsquo;t conforming are simply non-conformist and well that"™s a lost cause.  For the rest of us great work and keep it up!<br>
**Where is the Help!<br>
**
What I 
didn&rsquo;t
 see enough of in the advanced category is help.  Honestly if you"™re going to write a 200 line script fill out the help!  It"™s not that hard and it is THE difference between a good script and a great solution! It"™s also one of the fundamental differences between hacking and tool building, both are focused around automating a given problem set.  The hacker just gets it to work, the tool builder makes it usable by the masses.  If you haven"™t figured it out yet the real money is in tool building, I"™m just sayin!</p><p>**Trust but Validate.<br>
**
I was pleasantly surprised by the amount of error handling in this first round of submissions, however I was disappointed by the lack of parameter validation.  When done correctly parameter validation can remove most of the potential errors a script can run into, and the best part is you find out that it"™s not going to work before the script does anything!  For example in this week"™s scenario every single script was asked to supply a source and destination path.  The following would have removed all but an access denied error.</p><p><code>Param ( [Parameter(Mandatory=$true, ValuefrompipelineByPropertyName=$true)] [ValidateScript({Test-Path $_ -PathType Container})] [Alias("FullName")] [string]$Source , [Parameter(Mandatory=$true, ValuefrompipelineByPropertyName=$true)] [ValidateScript({Test-Path $_ -PathType Container})] [Alias("FullName")] [string]$Destination )</code>This is the equivalent of filter to the left, and 
I&rsquo;ve
 talked to endless developers who are a little jealous of our ability to use an arbitrary scriptblock for parameter validation. For more static values the ValidateSet attribute will perform the same function, but with the added benefit of Intelli-sense and tab completion.* Guys use this* I"™m telling you it"™s one of the most powerful features in PowerShell and I just don"™t see it use often enough, but then again<a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/15/simplify-your-powershell-script-with-parameter-validation.aspx"> I"™ve been tilting at this windmill for years now.</a></p><p>**Parameter names<br>
**
This one is a little more nitpicky than the average, but honestly there simply isn"™t an excuse for a script with three parameters to all start with the same letter.  Meaning the following is just disrespectful to yourself and your users.</p><p><code>Param( [String]$ArchiveSource, [String]$ArchiveDestination, [String]$ArchiveAge )</code>I mean that"™s a no-brainer right?  I don"™t assume malice here just a lack of focus.  Anyone who stops and thinks about it immediately sees the problem, and solution. So I guess what I"™m asking is that we collectively take a second to think about usability.  For those of you that haven"™t had your coffee yet. The solution is that since three parameters all contain Archive we need to move that bit from the beginning of each parameter name.   In this case since there is no real need to differentiate I would suggest removing it all together.</p><p><code>Param( [String]$Source, [String]$Destination, [String]$Age )</code>Here we"™re focusing on what"™s really important which makes the parameters easier to comprehend, but also lets us get to TAB faster which is a huge part of usability!<br>
**Bring it in<br>
**
In summary all in all I would say we had a fantastic showing for our industry this initial week.  I really like the new site and voting has been very productive which is nice.  As we head into week two I look forward to what"™s to come as we collectively build upon what we"™ve learned this week.</p><p>~Glenn</p>
]]></content:encoded></item><item><title>Scripting Games 2013: Event 1 "˜Favorite' and "˜Not So Favorite' Submissions</title><link>https://powershell.org/articles/2013-05-02-scripting-games-2013-event-1-favorite-and-not-so-favorite-submissions/</link><guid>https://powershell.org/articles/2013-05-02-scripting-games-2013-event-1-favorite-and-not-so-favorite-submissions/</guid><pubDate>Fri, 03 May 2013 03:07:27 +0000</pubDate><description>&lt;p&gt;As a follow-up to my &lt;a href="http://learn-powershell.net/2013/05/01/scripting-games-2013-thoughts-after-event-1/"&gt;previous blog&lt;/a&gt; post, I plan to pick out a submission or two or three which stood out as my personal favorite and least favorite and tell you why I think this by pointing pieces of code that was either put together nicely or could have been improved in one way or another. Depending on my time, I will do at least 1 Advanced and 1 Beginner submission for both &amp;ldquo;˜Favorite&amp;rdquo;™ and &amp;ldquo;˜Not so Favorite. I&amp;rsquo;ll start out by listing the code and then discussing it bullet point style to highlight my thoughts. So with that, lets begin this journey through the Event 1 submissions by &lt;a href="http://learn-powershell.net/2013/05/02/scripting-games-2013-event-1-favorite-and-not-so-favorite-submissions/"&gt;following this link to my blog!&lt;/a&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>As a follow-up to my<a href="http://learn-powershell.net/2013/05/01/scripting-games-2013-thoughts-after-event-1/">previous blog</a> post, I plan to pick out a submission or two or three which stood out as my personal favorite and least favorite and tell you why I think this by pointing pieces of code that was either put together nicely or could have been improved in one way or another. Depending on my time, I will do at least 1 Advanced and 1 Beginner submission for both &ldquo;˜Favorite&rdquo;™ and &ldquo;˜Not so Favorite. I&rsquo;ll start out by listing the code and then discussing it bullet point style to highlight my thoughts. So with that, lets begin this journey through the Event 1 submissions by<a href="http://learn-powershell.net/2013/05/02/scripting-games-2013-event-1-favorite-and-not-so-favorite-submissions/">following this link to my blog!</a></p>
]]></content:encoded></item><item><title>Event #1: Moving Old Files</title><link>https://powershell.org/articles/2013-05-02-event-1-moving-old-files/</link><guid>https://powershell.org/articles/2013-05-02-event-1-moving-old-files/</guid><pubDate>Thu, 02 May 2013 21:31:40 +0000</pubDate><description>&lt;p&gt;As a celebrity judge, I&amp;rsquo;m not required to blog &amp;ldquo;“ I&amp;rsquo;m just here for my good looks :&amp;gt; &amp;ndash; but I&amp;rsquo;m having a great time reading the blogs posted by the Expert Judges about the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/25/2013-scripting-games-beginner-event-1.aspx"&gt;Event #1&lt;/a&gt; candidate solutions.  Much of the judging is subjective, but I&amp;rsquo;ll add the criteria that I use to distinguish a working solution from a great solution.&lt;br&gt;
Before I do, though, I want to congratulate everyone who submitted an entry. Most of the entries work and you probably learned just from playing with the challenge. Keep it up and come back year after year.&lt;br&gt;
One hint to everyone: &lt;strong&gt;TEST!&lt;/strong&gt; Most of the entries work, but many fail if the directory for the application (e.g. App1 in \NASServer\Archives\App1) does not already exist. And, a few fail with regular expression errors on the Replace operator (more in the blog). There are lots of great test strategies, but you can just run your code on file in your own directories or step through the code in the Windows PowerShell ISE debugger.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>As a celebrity judge, I&rsquo;m not required to blog &ldquo;“ I&rsquo;m just here for my good looks :&gt; &ndash; but I&rsquo;m having a great time reading the blogs posted by the Expert Judges about the<a href="http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/25/2013-scripting-games-beginner-event-1.aspx">Event #1</a> candidate solutions.  Much of the judging is subjective, but I&rsquo;ll add the criteria that I use to distinguish a working solution from a great solution.<br>
Before I do, though, I want to congratulate everyone who submitted an entry. Most of the entries work and you probably learned just from playing with the challenge. Keep it up and come back year after year.<br>
One hint to everyone:<strong>TEST!</strong> Most of the entries work, but many fail if the directory for the application (e.g. App1 in \NASServer\Archives\App1) does not already exist. And, a few fail with regular expression errors on the Replace operator (more in the blog). There are lots of great test strategies, but you can just run your code on file in your own directories or step through the code in the Windows PowerShell ISE debugger.</p><h2 id="get-help-an-archival-atrocity" class="ps-heading">Get-Help: An Archival Atrocity<a class="ps-heading-anchor" href="#get-help-an-archival-atrocity" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Let&rsquo;s start with a quick review of the event challenge. You can read the beginner challenge<a href="http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/25/2013-scripting-games-beginner-event-1.aspx">here</a>.<br>
Basically, the task is to move log files older than 90 days old from their current locations in application-specific subdirectories of C:\Application\Log  (such as C:\Application\Log\.log) to an archive share, \NASServer\Archives.<br>
The files have GUID filenames (read: you can&rsquo;t predict them). You need to maintain the subdirectory structure, so if a log file starts in the App582 subdirectory of C:\Application\Log, after the move, it should be in the App852 subdirectory of NASServer\Archives.<br>
The final instruction/hint is that the applications generate the files and never touch them again. I&rsquo;m not an expert, but I interpreted this to mean that the CreationTime property and the LastWriteTime property of these log files will be the same and you can use either in your solution. (Is that right?)<br>
The advanced challenge involves the same task, but generalized into a reusable tool, so you want to create a script with parameters for the log path and archive paths. This is one of those advanced challenges that many beginners should be able to do. For giggles, try it on your beginner solution.<br>
To recap, here are the elements of this challenge and solutions, all of which I think are acceptable in a beginner challenge.</p><ul><li>Find the log files</li><li>Get only the ones that are at least 90 days old (CreationTime or LastWriteTime)</li><li>Move them to the same subdirectory in the archive directory</li></ul><p>Finding the log files is pretty easy:</p><p><code>Get-ChildItem C:\Application\Log\*.log "“Recurse Get-ChildItem C:\Application\Log -Include *.log "“Recurse Get-ChildItem C:\Application\Log -Filter *.log "“Recurse Get-ChildItem C:\Application\Log\ *\*.log</code>Calculating 90 days is only a bit harder:</p><p><code>(Get-Date).AddDays(-90) #Yes, a negative number! (Get-Date).Subtract(New-TimeSpan -Days 90) ((Get-Date) - $file.LastWriteTime).Days -gt 90</code>Because the only really tricky part in this challenge is moving the file and maintaining the directory structure, I&rsquo;m concentrating on that part.</p><ul><li>First,  you need to get the current subdirectory and make sure the file goes in that same subdirectory in the new location.</li><li>Second, if you try to copy or move an item to a directory that doesn&rsquo;t exist, the command fails &ldquo;“ and the Force parameter will not build the path for you.</li></ul><h2 id="get-myvote" class="ps-heading">Get-MyVote<a class="ps-heading-anchor" href="#get-myvote" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Here are the elements that I look for in a solution.</p><ul><li><strong>Preserve the path</strong>:  I look for solutions that preserve or build the new path correctly. This is required by the challenge, but it&rsquo;s also a place for some creativity.</li><li><strong>Test-Path/New-Item</strong>: I look for solutions that test to see if the path exists in the new location (Test-Path) and creates the directories in the path if they don&rsquo;t already exist, typically by using Mkdir (md) or New-Item &ldquo;“Type Directory.</li><li><strong>New-Item | Out-Null</strong>:  When you create a new path, New-Item and Mkdir return a directory object. This can be confusing to users who run your script, so I give extra points for suppressing the output. I typically do this by piping the output to Out-Null. Here&rsquo;s a possible solution, but I&rsquo;m open to creative variation.</li></ul><p><code>New-Item -Type Directory -Path C:\Application\Log\$p | Out-Null</code>*<strong>Help</strong> (of course). More below</p><ul><li><strong>Test.</strong> Don&rsquo;t share a solution that you haven&rsquo;t tested. There are many ways to test, but running the solution on datasets with different elements is a great way. I always run my code in the Windows PowerShell ISE debugger before using it or sharing it. ****</li></ul><h2 id="get-help" class="ps-heading">Get-Help<a class="ps-heading-anchor" href="#get-help" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>All shared functions and scripts should have help. Help helps the end user and makes the script maintainable. Unless you plan a use a command once and toss it, you need help.<br>
Comment-based help for a simple script like this is easy to write:<br>
&lt;#</p><p><code>.SYNOPSIS Move-Oldfiles.ps1 By juneb 4/25/2013 .DESCRIPTION Moves files that are at least 90 days old from a subdirectory of C:\Application\Log to the same subdirectory in NASServer\Archives. .EXAMPLE Move-OldFiles.ps1</code>#&gt;<br>
Additional comments are great, especially if you&rsquo;re doing something clever. For example, if you use the $Path.Directory.Name to get the path (thanks to<a href="http://becomelotr.wordpress.com/2013/04/30/event-1-my-way/">Bartek Bielawski</a> for this hint), a comment that it gets only the immediate parent directory would be very helpful to someone reading the script.<br>
I actually deduct points for &ldquo;help&rdquo; that Get-Help can&rsquo;t get, such as this sort of stuff:</p><p>`# This script moves files that are older than 90 days</p><h1 id="old-from-a-subdirectory-of-capplicationlog-to-the" class="ps-heading">old from a subdirectory of C:\Application\Log to the<a class="ps-heading-anchor" href="#old-from-a-subdirectory-of-capplicationlog-to-the" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><h1 id="same-subdirectory-in-nasserverarchives-i-wrote-it" class="ps-heading">same subdirectory in NASServer\Archives. I wrote it<a class="ps-heading-anchor" href="#same-subdirectory-in-nasserverarchives-i-wrote-it" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><h1 id="for-scripting-games-2013-event-1" class="ps-heading">for Scripting Games 2013, Event 1<a class="ps-heading-anchor" href="#for-scripting-games-2013-event-1" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h1><p>`It&rsquo;s so easy to do it right that doing it wrong is pretty silly.</p><h2 id="efficiency-calculating-90-days" class="ps-heading">Efficiency: Calculating 90 Days<a class="ps-heading-anchor" href="#efficiency-calculating-90-days" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>I&rsquo;ve seen a lot of this approach in solutions, usually in one-liners.</p><p><code>Get-ChildItem C:\Application\Log\*\*.log | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-90)} | Move-Item -Destination ...</code>This approach recalculates the archive date FOR EVERY FILE. That would make sense only if the script took more than a day to run. Computers are pretty fast these days, but there&rsquo;s no reason to be purposefully inefficient. It&rsquo;s much better to calculate the archive date once, save it, and reuse it.</p><p><code>$ArchiveDate = (Get-Date).AddDays(-90) Get-ChildItem C:\Application\Log\*\*.log | Where-Object {$_.LastWriteTime -lt $ArchiveDate} | Move-Item -Destination ...</code>## Get-ChildItem: -File, -Directory -Hidden -ReadOnly, -Attributes</p><p>The FileSystem provider in Windows PowerShell 3.0 adds awesome new parameters to the Get-ChildItem cmdlet. For help, Get-Help<a href="http://technet.microsoft.com/en-us/library/hh847897.aspx">Get-ChildItem for FileSystem</a>. I give extra points to people who use them correctly and deduct points for the more old-fashioned PSISContainer.<br>
The following code works:</p><p><code>Get-ChildItem C:\Application\Log -Recurse | Where-Object {$_.PSIsContainer}</code>But the preferred version uses the new features and it is really much easier to interpret:</p><p><code>Get-ChildItem C:\Application\Log -Directory -Recurse</code>On the same note, I noticed the following:</p><p><code>Get-ChildItem -Attributes D ...</code>Like a lot of solutions, this works &ndash; it gets only directories in the path &ndash; but it&rsquo;s more confusing than the simpler equivalent:</p><p><code>Get-ChildItem -Directory</code>The Attributes parameter is designed for attribute combinations and for attributes that cannot be expressed with the simpler parameters, like this expression, which gets files that are compressed and not hidden.</p><p><code>Get-ChildItem -File -Attributes Compressed+!Hidden</code>## Regular Expressions in Replace Statements</p><p>One of the tricky parts of this challenge was preserving the original path in the new archive directory. There were many clever ways to do this. But several (presumably untested) solutions will fail with a regular expression error.<br>
For example:</p><p><code>foreach ($file in $files) { $newName = $file.fullname -replace 'C:\Application\Log','\\NASServer\Archives' move-item -Destination $newName }</code>Generates this error:</p><p>`Regular expression pattern is not valid: C:\Application\Log.
At C:\ps-test\ScriptingGames2013\Move-TestEsc.ps1:5 char:5
+     $newName = $file.fullname -replace &lsquo;C:\Application\Log&rsquo;,&rsquo;\NASServer\Archive &hellip;
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p><ul><li>CategoryInfo          : InvalidOperation: (C:\Application\Log:String) [], RuntimeException</li><li>FullyQualifiedErrorId : InvalidRegularExpression
`The problem here is that you didn&rsquo;t intend to supply a regular expression as input, but the Replace operator interprets the text that it is replacing (the first operand) as a regular expression. In this case, it interprets the backslashes as escape characters.  To resolve the error, escape the backslashes by doubling them, that is, preceding each backslash with another backslash.<br>
For example:</li></ul><p><code>-replace 'C:\\Application\\Log' ...</code>Here is the corrected code:</p><p><code>foreach ($file in $files) { $newName = $file.fullname -replace 'C:\\Application\\Log','\\NASServer\Archives' move-item -Destination $newName }</code>You don&rsquo;t need to escape the backslash in the replacement text (second operand), because the Replace operator doesn&rsquo;t interpret that text as a regular expression. It just pastes it.<br>
NOTE: The<a href="http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx">Replace method of strings</a> does not use regular expressions, so you don&rsquo;t need to worry about those backslashes.</p><p><code>$newName = ($file.fullname).Replace('C:\ps-test','\\NASServer\Archives')</code>## Simplify Booleans</p><p>Here&rsquo;s a very frequent pattern:</p><p><code>if ($a -eq $true) {} elseif ($a -eq $false) {}</code>But notice that:</p><p><code>$a -eq $true</code>Is equivalent to:</p><p><code>$a</code>Similarly:</p><p><code>$a -eq $false</code>Is equivalent to:</p><p><code>!$a</code>And, if $a is not true, the only alternative, is that it&rsquo;s false. So you can simplify that original code to:</p><p><code>if ($a) {} else {}</code>So, when you see yourself typing:</p><p><code>Where {$_.PSIsContainer -eq $true}</code>You can react immediately and change it to:</p><p><code>Where {$_.PSIsContainer }</code>Or change:</p><p><code>$_.PsISContainer -ne $True</code>To:</p><p><code>!$_.PsISContainer</code>A side note: In some languages, $a is true if it contains a true statement or any numeric value other than zero. In Windows PowerShell $a is true if it contains a true statement or a value of 1; otherwise, it is false.</p><h2 id="enumerating-the-paths" class="ps-heading">Enumerating the paths<a class="ps-heading-anchor" href="#enumerating-the-paths" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Many of the solutions included enumerated paths, like this:</p><p><code>Get-Childitem -Path "C:\Application\Log\App1",</code>
&ldquo;C:\Application\Log\OtherApp&rdquo;,<code>"C:\Application\Log\OtherApp" -Recurse ...</code>I feel badly, but I think these folks misinterpreted examples to be absolute paths. It&rsquo;s really important for us to write the challenges clearly and unambiguously, especially because we have a truly international audience, but participants need to read carefully, too.</p><h2 id="dont-use-aliases" class="ps-heading">Don&rsquo;t use aliases<a class="ps-heading-anchor" href="#dont-use-aliases" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Aliases are terrific for interactive commands and commands that you don&rsquo;t share with others. But for anything else, including the Scritping Games, avoid them. Can you imagine a beginner trying to intepret a solution in which &ldquo;?&rdquo; is used instead of Where-Object? How would the person search for that &ldquo;?"?  Because understanding is the goal, I have no trouble with eliminating the &ldquo;Object&rdquo; in Where-Object, Sort-Object, Select-Object, but it&rsquo;s better to leave it in.<br>
In general, you should also include the names of positional parameters, although I don&rsquo;t mind omitting the most frequently used ones. Other people might be pickier, but I don&rsquo;t use &ldquo;Where-Object -Property&rdquo; or &ldquo;Get-ChildItem -Path&rdquo; in my own code and I don&rsquo;t require it from others.</p><h2 id="one-liners" class="ps-heading">One-Liners<a class="ps-heading-anchor" href="#one-liners" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>A final note: one-liners are very useful, but I don&rsquo;t count lines of code or characters in a command when evaluating solutions. Solutions that use fancy regular expression statements are impressive but they can be difficult to interpret and maintain. If you can get your code onto one line, that&rsquo;s terrific, but it&rsquo;s not necessary and I don&rsquo;t give it any extra points.<br>
Now, we can get ready for Event #2. Good luck, everyone!</p>
]]></content:encoded></item><item><title>Judge Notes for Event 1</title><link>https://powershell.org/articles/2013-05-02-judge-notes-for-event-1/</link><guid>https://powershell.org/articles/2013-05-02-judge-notes-for-event-1/</guid><pubDate>Thu, 02 May 2013 17:24:49 +0000</pubDate><description>&lt;p&gt; A lot of you have been working too hard at solving the problem (both beginner and advanced). Some of this is clearly related to trying to offer a very complete solution but some look like attempts to write extra clever or elegant code. In the &amp;ldquo;real world&amp;rdquo;, there&amp;quot;™s probably not enough time or interest in putting lots of effort into these extras. The minimum it takes to achieve the goal is most often good enough. Here are a couple of examples to illustrate this (with the intent of providing a learning opportunity).&lt;br&gt;
Working with the destination folder address.&lt;br&gt;
A common error here was missing the subdirectory. Most folks got this correct by using some version of &lt;em&gt;$&lt;/em&gt;.FullName.Replace(&amp;quot;˜C:\Application\Log&amp;quot;™,&amp;quot;™\NASServer\Archives&amp;quot;™)_ or &lt;em&gt;Join-Path &amp;ldquo;˜\NASServer\Archives&amp;rdquo;™ $&lt;/em&gt;.Directory.Name_, but there were a number who just used the root destination folder name without looking for the subfolder. And some others had solutions that (although I thought were innovative), took too much effort. Among them are:&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p> A lot of you have been working too hard at solving the problem (both beginner and advanced). Some of this is clearly related to trying to offer a very complete solution but some look like attempts to write extra clever or elegant code. In the &ldquo;real world&rdquo;, there"™s probably not enough time or interest in putting lots of effort into these extras. The minimum it takes to achieve the goal is most often good enough. Here are a couple of examples to illustrate this (with the intent of providing a learning opportunity).<br>
Working with the destination folder address.<br>
A common error here was missing the subdirectory. Most folks got this correct by using some version of<em>$</em>.FullName.Replace("˜C:\Application\Log"™,"™\NASServer\Archives"™)_ or<em>Join-Path &ldquo;˜\NASServer\Archives&rdquo;™ $</em>.Directory.Name_, but there were a number who just used the root destination folder name without looking for the subfolder. And some others had solutions that (although I thought were innovative), took too much effort. Among them are:</p><p><code>Join-Path "˜\\NASServer\Archives"™ ($_.Directory.Split("˜\"™)[-1]) $_.FullName "“Replace [regex]::Escape("˜C:\Application\Log"™,"™\\NASServer\Archives"™)</code>Once computing the destination, most solutions checked to see if the folder existed and created it if it was missing. But some just tried to create it anyway (too much effort) and others who did not (too little effort).<br>
I"™m not going to comment on the use of Copy-Object vs. Move-Object other than to say that (related to the destination folder) it looks like some people thought the cmdlets would create the path structure but never tested to see that they don"™t. Don&rsquo;t forget to test your solution to verify that it works: working code is far more important that &ldquo;pretty&rdquo; or &ldquo;elegant&rdquo; code.<br><strong>Using Try-Catch-Finally.</strong><br>
Try-Catch-Finally is an awesomely potent construct but you really need to understand how it works. Here&rsquo;s why I think it is serious overkill for this problem. Compare these:</p><p><code>If (-not (Test-Path $DestinationFolder)) {New-Item "“ItemType Directory "“Path $DestinationFolder}</code>Try {Test-Path $DestinationFolder &ldquo;“ErrorAction Stop} Catch {New-Item &ldquo;“ItemType Directory &ldquo;“Path $DestinationFolder}
`Look the same, right? But they have very different results, not to mention different typing efforts. If the destination folder does not exist, then with IF, the folder gets created, but with Try-Catch it will not. This is because Test-Path will return $false, but NO error, so the catch clause will never execute.<br>
Most folks understand that a terminating error has to occur in the Try script block in order for the Catch block to execute. But, instead of using the &ldquo;“ErrorAction Stop parameter in the cmdlet, some of the solutions set $ErrorActionPreference to Stop and then reset it to Continue in a Finally block. There are two problems with this. First, it forces every command in the Try block to generate terminating errors, when there&rdquo;™s normally only one that you care about. Second, $ErrorActionPreference might not have been originally set to Continue. Shouldn&rdquo;™t the previous value be saved and then restored in Finally?<br>
So, going forward, think about how hard you&rdquo;™re working to get to an answer. Don&rdquo;™t use a more complex method than you need to in order to solve a problem. Make good use of Get-Help to verify the parameters and outputs of the cmdlets that you use. And test your objects with Format-List and Get-Member to make sure that the properties really are what you think they are.</p>
]]></content:encoded></item><item><title>Event 2 Opens / Event 1 Winding Down</title><link>https://powershell.org/articles/2013-05-02-event-2-opens-event-1-winding-down/</link><guid>https://powershell.org/articles/2013-05-02-event-2-opens-event-1-winding-down/</guid><pubDate>Thu, 02 May 2013 14:25:12 +0000</pubDate><description>&lt;p&gt;Event 2 is scheduled to open this evening in The Scripting Games - &lt;em&gt;remember, all times on the &lt;a href="http://scriptinggames.org/"&gt;Scripting Games Web site&lt;/a&gt; are GMT.&lt;/em&gt; You will need to adjust for your local time zone.&lt;br&gt;
Voting on Event 1 is scheduled to end on May 7th, so you still have 5 days to earn pointlets and leave comments for your colleagues. As of right now, we have over 330 entries, and an astounding 4,900 votes - an average ratio of more than 14 votes per entry. Folks, that&amp;rsquo;s &lt;em&gt;seven times more&lt;/em&gt; than we&amp;rsquo;ve been able to provide in the past by just having &amp;ldquo;expert judges&amp;rdquo; voting.&lt;br&gt;
Those experts are now being put to better use, providing the learning experience we so much want to deliver. They&amp;rsquo;re posting in their own blogs (&lt;a href="https://powershell.org/the-scripting-games/scripting-games-judges-notes/"&gt;list&lt;/a&gt;) as well as &lt;a href="https://powershell.org/category/announcements/scripting-games/judges-notes/"&gt;here on PowerShell.org&lt;/a&gt;, and there&amp;rsquo;s a lot to read. I&amp;rsquo;m delighted that we&amp;rsquo;ve been able to provide so much commentary before Event 2 starts, since that&amp;rsquo;ll doubtlessly help everyone do better.&lt;br&gt;
The average CrowdScore is 2.551 per entry - obviously there&amp;rsquo;s everything from 1-point entries to 5-point entries. Folks are being pretty critical, and identifying things they don&amp;rsquo;t like, as well as things they do. With more than 1800 comments (that&amp;rsquo;s an average of more than 5 per entry), hopefully competitors are starting to get some take-aways from the community as well.&lt;br&gt;
On Mighty Panel of Celebrity Judges will start awarding first, second, and third place in Event 1 very soon, and that process will take a few days. Keep in mind that their decisions are in no way connected to the community-based CrowdScore. Instead, they&amp;rsquo;re exploring entries on their own, stating with the ones &amp;ldquo;favorited&amp;rdquo; by our expert commentary judges.&lt;br&gt;
Also, I&amp;rsquo;ve heard some concern about people trying to &amp;ldquo;cheat&amp;rdquo; the system by simply dropping in random votes in order to rack up pointlets and win prizes. We&amp;rsquo;re watching for that - we log IP addresses, vote times, and a lot of other data. We&amp;rsquo;ll be filtering the votes before awarding prizes, so there&amp;rsquo;s just no value in cheating. &lt;em&gt;You won&amp;rsquo;t see that filtering -&lt;/em&gt; we&amp;rsquo;re doing it on an offline copy of the data so that there&amp;rsquo;s no chance of accidentally deleting anything valuable - but you&amp;rsquo;ll also be happy to know that, right now, there&amp;rsquo;s very little in the way of anything suspicious, and nothing that&amp;rsquo;s been confirmed.&lt;br&gt;
I want to re-emphasize that the CrowdScore activity doesn&amp;rsquo;t become a true learning experience until &lt;em&gt;after the Games are over,&lt;/em&gt; which is when we can start mining that data and divining some crowdsourced best practices and patterns - creating our own community sense of &amp;ldquo;right and wrong&amp;rdquo; in PowerShell. I also want to point out that, after the Games, we&amp;rsquo;ll be posting all entries, and their comments, into easier-to-download archives (I know the Web site doesn&amp;rsquo;t make copy n paste super-easy; that&amp;rsquo;s largely an artifact of what we need to do to display things properly; we&amp;rsquo;re not offering downloads at this time mainly to control server load).&lt;br&gt;
Enjoy Event 2!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Event 2 is scheduled to open this evening in The Scripting Games -<em>remember, all times on the<a href="http://scriptinggames.org/">Scripting Games Web site</a> are GMT.</em> You will need to adjust for your local time zone.<br>
Voting on Event 1 is scheduled to end on May 7th, so you still have 5 days to earn pointlets and leave comments for your colleagues. As of right now, we have over 330 entries, and an astounding 4,900 votes - an average ratio of more than 14 votes per entry. Folks, that&rsquo;s<em>seven times more</em> than we&rsquo;ve been able to provide in the past by just having &ldquo;expert judges&rdquo; voting.<br>
Those experts are now being put to better use, providing the learning experience we so much want to deliver. They&rsquo;re posting in their own blogs (<a href="https://powershell.org/the-scripting-games/scripting-games-judges-notes/">list</a>) as well as<a href="https://powershell.org/category/announcements/scripting-games/judges-notes/">here on PowerShell.org</a>, and there&rsquo;s a lot to read. I&rsquo;m delighted that we&rsquo;ve been able to provide so much commentary before Event 2 starts, since that&rsquo;ll doubtlessly help everyone do better.<br>
The average CrowdScore is 2.551 per entry - obviously there&rsquo;s everything from 1-point entries to 5-point entries. Folks are being pretty critical, and identifying things they don&rsquo;t like, as well as things they do. With more than 1800 comments (that&rsquo;s an average of more than 5 per entry), hopefully competitors are starting to get some take-aways from the community as well.<br>
On Mighty Panel of Celebrity Judges will start awarding first, second, and third place in Event 1 very soon, and that process will take a few days. Keep in mind that their decisions are in no way connected to the community-based CrowdScore. Instead, they&rsquo;re exploring entries on their own, stating with the ones &ldquo;favorited&rdquo; by our expert commentary judges.<br>
Also, I&rsquo;ve heard some concern about people trying to &ldquo;cheat&rdquo; the system by simply dropping in random votes in order to rack up pointlets and win prizes. We&rsquo;re watching for that - we log IP addresses, vote times, and a lot of other data. We&rsquo;ll be filtering the votes before awarding prizes, so there&rsquo;s just no value in cheating.<em>You won&rsquo;t see that filtering -</em> we&rsquo;re doing it on an offline copy of the data so that there&rsquo;s no chance of accidentally deleting anything valuable - but you&rsquo;ll also be happy to know that, right now, there&rsquo;s very little in the way of anything suspicious, and nothing that&rsquo;s been confirmed.<br>
I want to re-emphasize that the CrowdScore activity doesn&rsquo;t become a true learning experience until<em>after the Games are over,</em> which is when we can start mining that data and divining some crowdsourced best practices and patterns - creating our own community sense of &ldquo;right and wrong&rdquo; in PowerShell. I also want to point out that, after the Games, we&rsquo;ll be posting all entries, and their comments, into easier-to-download archives (I know the Web site doesn&rsquo;t make copy n paste super-easy; that&rsquo;s largely an artifact of what we need to do to display things properly; we&rsquo;re not offering downloads at this time mainly to control server load).<br>
Enjoy Event 2!</p>
]]></content:encoded></item><item><title>Few notes written after event 1.</title><link>https://powershell.org/articles/2013-05-01-few-notes-written-after-event-1/</link><guid>https://powershell.org/articles/2013-05-01-few-notes-written-after-event-1/</guid><pubDate>Thu, 02 May 2013 06:48:11 +0000</pubDate><description>&lt;p&gt;As promised, today more general thoughts on scripts I&amp;rsquo;ve seen in both categories in the first event. I&amp;rsquo;m Polish, so I decided to blog notes both in my own language, and in English, &amp;ldquo;just in case&amp;rdquo;. Also, my Polish is much better than my English (I hope!), so for people from Poland: they can read Polish version, without the pain of translating my-English to English-English. Enjoy!&lt;br&gt;
&lt;a href="http://becomelotr.wordpress.com/2013/05/02/event-1-my-notes/"&gt;English version&lt;/a&gt;&lt;br&gt;
&lt;a href="http://powershellpl.net/2013/05/02/scripting-games-moje-notatki-1/"&gt;Polish version&lt;/a&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>As promised, today more general thoughts on scripts I&rsquo;ve seen in both categories in the first event. I&rsquo;m Polish, so I decided to blog notes both in my own language, and in English, &ldquo;just in case&rdquo;. Also, my Polish is much better than my English (I hope!), so for people from Poland: they can read Polish version, without the pain of translating my-English to English-English. Enjoy!<br><a href="http://becomelotr.wordpress.com/2013/05/02/event-1-my-notes/">English version</a><br><a href="http://powershellpl.net/2013/05/02/scripting-games-moje-notatki-1/">Polish version</a></p>
]]></content:encoded></item><item><title>Scripting Games 2013: Thoughts After Event 1</title><link>https://powershell.org/articles/2013-05-01-scripting-games-2013-thoughts-after-event-1/</link><guid>https://powershell.org/articles/2013-05-01-scripting-games-2013-thoughts-after-event-1/</guid><pubDate>Thu, 02 May 2013 02:21:16 +0000</pubDate><description>&lt;p&gt;With Event 1 in the books for the 2013 Scripting Games, we are now in the voting period where the community gets the chance to play judge on all of the scripts submitted by voting and commenting on the submissions. I aim to take a look at the common items that pose problems and recommendations on what to do to fix this. The full article is available &lt;a href="http://learn-powershell.net/2013/05/01/scripting-games-2013-thoughts-after-event-1/"&gt;here&lt;/a&gt;.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>With Event 1 in the books for the 2013 Scripting Games, we are now in the voting period where the community gets the chance to play judge on all of the scripts submitted by voting and commenting on the submissions. I aim to take a look at the common items that pose problems and recommendations on what to do to fix this. The full article is available<a href="http://learn-powershell.net/2013/05/01/scripting-games-2013-thoughts-after-event-1/">here</a>.</p>
]]></content:encoded></item><item><title>Do you really Support Should Process…?</title><link>https://powershell.org/articles/2013-05-01-do-you-really-support-should-process/</link><guid>https://powershell.org/articles/2013-05-01-do-you-really-support-should-process/</guid><pubDate>Wed, 01 May 2013 22:02:38 +0000</pubDate><description>&lt;p&gt;While working on my notes for first event of Scripting Games I was looking around what others wrote, and was surprised that people really think that enabling SupportsShouldProcess is good enough. In my opinion - it is not. And because this is relatively big topic I decided to write separate blog post just about that. You can find it &lt;a href="http://becomelotr.wordpress.com/2013/05/01/supports-should-process-oh-really/"&gt;here&lt;/a&gt;. I hope it will highlight the difference between &lt;strong&gt;enabling&lt;/strong&gt; this feature and actually &lt;strong&gt;implementing&lt;/strong&gt; it. And remember: &lt;strong&gt;do not&lt;/strong&gt; kill the messenger. 😉 More from me (mainly on other topics related to first event) tomorrow.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>While working on my notes for first event of Scripting Games I was looking around what others wrote, and was surprised that people really think that enabling SupportsShouldProcess is good enough. In my opinion - it is not. And because this is relatively big topic I decided to write separate blog post just about that. You can find it<a href="http://becomelotr.wordpress.com/2013/05/01/supports-should-process-oh-really/">here</a>. I hope it will highlight the difference between<strong>enabling</strong> this feature and actually<strong>implementing</strong> it. And remember:<strong>do not</strong> kill the messenger. 😉 More from me (mainly on other topics related to first event) tomorrow.</p>
]]></content:encoded></item><item><title>And the Norweigian judge says…</title><link>https://powershell.org/articles/2013-05-01-and-the-norweigian-judge-says/</link><guid>https://powershell.org/articles/2013-05-01-and-the-norweigian-judge-says/</guid><pubDate>Wed, 01 May 2013 20:22:12 +0000</pubDate><description>&lt;p&gt;Jan Egil Ring weighs in with his thoughts on Event 1: &lt;a href="http://blog.powershell.no/category/2013-Scripting-Games-Judges-Notes/feed/"&gt;http://blog.powershell.no/category/2013-Scripting-Games-Judges-Notes/feed/&lt;/a&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Jan Egil Ring weighs in with his thoughts on Event 1:<a href="http://blog.powershell.no/category/2013-Scripting-Games-Judges-Notes/feed/">http://blog.powershell.no/category/2013-Scripting-Games-Judges-Notes/feed/</a></p>
]]></content:encoded></item><item><title>Why Doesn't My ValidateScript() work correctly?</title><link>https://powershell.org/articles/2013-05-01-why-doesnt-my-validatescript-work-correctly/</link><guid>https://powershell.org/articles/2013-05-01-why-doesnt-my-validatescript-work-correctly/</guid><pubDate>Wed, 01 May 2013 13:52:06 +0000</pubDate><description>&lt;p&gt;I&amp;rsquo;ve received a few comments from folks after my observations on the Scripting Games Event 1. In those observations, I noted how much I loved:&lt;br&gt;
&lt;strong&gt;[ValidateScript({Test-Path $_})][string]$path&lt;/strong&gt;&lt;br&gt;
As a way of testing to make sure your -Path parameter got a valid value, I love this. I&amp;rsquo;d never thought of it, and I plan to use it in classes. I may write a book about it someday, or maybe even an ode. Seriously good logic. But&amp;hellip; I also bemoaned some scripts that provided an additional Test-Path, in the script&amp;rsquo;s main body of code. Why have a redundant check?&lt;br&gt;
So, first, thanks for the e-mails you all sent. Second&amp;hellip; please understand that I can&amp;rsquo;t respond to you all. I&amp;rsquo;ve got this full-time job thing, and I&amp;rsquo;ve &lt;em&gt;got&lt;/em&gt; to do it or the grocery store will stop taking our checks. You&amp;rsquo;re &lt;em&gt;welcome&lt;/em&gt; to drop comments here, and I &lt;em&gt;really appreciate&lt;/em&gt; when you say stuff like, &amp;ldquo;can you explain ___ in a future post?&amp;rdquo; because it gives me ideas to write about. I just can&amp;rsquo;t get into private e-mail based education for a dozen folks. Teaching is kinda what I do for my job, so most of my time has to go to that.&lt;br&gt;
But - there&amp;rsquo;s a great teaching point here. Let&amp;rsquo;s take this example:&lt;br&gt;
&lt;a href="https://powershell.org/wp-content/uploads/2013/05/valid-default-path.png"&gt;&lt;img src="https://powershell.org/wp-content/uploads/2013/05/valid-default-path.png" alt="valid-default-path"&gt;&lt;/a&gt;&lt;br&gt;
This works as you would hopefully expect. When given a valid path, it&amp;rsquo;s fine. When allowed to use a valid default, it&amp;rsquo;s fine. When given an invalid path, it barfs in the ValidateScript. Now look at the next example - which more closely approximates what people have been seeing in their Scripting Games scripts:&lt;br&gt;
&lt;a href="https://powershell.org/wp-content/uploads/2013/05/invalid-default-path.png"&gt;&lt;img src="https://powershell.org/wp-content/uploads/2013/05/invalid-default-path.png" alt="invalid-default-path"&gt;&lt;/a&gt;&lt;br&gt;
In the Games, you were given a default path that &lt;em&gt;wasn&amp;rsquo;t valid on your computer.&lt;/em&gt; So folks allowed their script to run with that default, and got errors, and were annoyed that ValidateScript() didn&amp;rsquo;t catch the problem.&lt;br&gt;
It never will.&lt;br&gt;
When you run a command, PowerShell goes through a process called parameter binding, wherein it attaches values to parameters and runs any declarative validation - like ValidateScript(). That validation will &lt;em&gt;always&lt;/em&gt; catch invalid incoming data that&amp;rsquo;s been manually specified or sent in via the pipeline (for parameters that accept pipeline input). Because my -Path parameter wasn&amp;rsquo;t declared as mandatory, the validation routine will let me run the script and not specify -path.&lt;br&gt;
&lt;em&gt;Then&lt;/em&gt; the shell actually &lt;em&gt;runs&lt;/em&gt; my code - and &lt;em&gt;that&amp;rsquo;s&lt;/em&gt; when it assigns the default value to $path if one wasn&amp;rsquo;t specified on -path. Validation is over by this point, so an invalid default value will sneak by. The assumption by the shell is that &lt;em&gt;you&amp;rsquo;re&lt;/em&gt; providing the default value, so &lt;em&gt;you&amp;rsquo;re&lt;/em&gt; smart enough to provide a valid one. If you don&amp;rsquo;t, it&amp;rsquo;s your problem.&lt;br&gt;
So do you just add a second, in-code check for the parameter? I&amp;rsquo;d still say no. I really dislike redundancy. If you know, because of your situation, that you can&amp;rsquo;t rely on ValidateScript(), then don&amp;rsquo;t use it at all - one check should suffice, and if it needs to be in-code instead of declarative, that&amp;rsquo;s fine. What&amp;rsquo;d be nice is if there was a declarative way of specifying a default, like &lt;strong&gt;[Default(&amp;lsquo;whatever&amp;rsquo;)]&lt;/strong&gt; that ran before the validation checks, but such a thing doesn&amp;rsquo;t exist. Frankly, you could probably argue that if you can&amp;rsquo;t guarantee the validity of a default, then you shouldn&amp;rsquo;t provide one - and I&amp;rsquo;d probably buy into that argument, and subscribe to your newsletter.&lt;br&gt;
In this case, the problem is entirely artificial. The default path value given to you in the Games scenario &lt;em&gt;is&lt;/em&gt; valid &lt;em&gt;in the context of the Games;&lt;/em&gt; it&amp;rsquo;s just when you test it on &lt;em&gt;your&lt;/em&gt; system, &lt;em&gt;outside&lt;/em&gt; that context, that a problem crops up.&lt;br&gt;
Hopefully this helps explain how the ValidateXXX() attributes work, and how they interact with other features, like a default value.&lt;br&gt;
&lt;em&gt;Now&lt;/em&gt; explain why this will never assign C:\ as a default value:&lt;br&gt;
&lt;strong&gt;[Parameter(Mandatory=$True)][string]$path = &amp;lsquo;c:'&lt;/strong&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I&rsquo;ve received a few comments from folks after my observations on the Scripting Games Event 1. In those observations, I noted how much I loved:<br><strong>[ValidateScript({Test-Path $_})][string]$path</strong><br>
As a way of testing to make sure your -Path parameter got a valid value, I love this. I&rsquo;d never thought of it, and I plan to use it in classes. I may write a book about it someday, or maybe even an ode. Seriously good logic. But&hellip; I also bemoaned some scripts that provided an additional Test-Path, in the script&rsquo;s main body of code. Why have a redundant check?<br>
So, first, thanks for the e-mails you all sent. Second&hellip; please understand that I can&rsquo;t respond to you all. I&rsquo;ve got this full-time job thing, and I&rsquo;ve<em>got</em> to do it or the grocery store will stop taking our checks. You&rsquo;re<em>welcome</em> to drop comments here, and I<em>really appreciate</em> when you say stuff like, &ldquo;can you explain ___ in a future post?&rdquo; because it gives me ideas to write about. I just can&rsquo;t get into private e-mail based education for a dozen folks. Teaching is kinda what I do for my job, so most of my time has to go to that.<br>
But - there&rsquo;s a great teaching point here. Let&rsquo;s take this example:<br><a href="https://powershell.org/wp-content/uploads/2013/05/valid-default-path.png"><img src="https://powershell.org/wp-content/uploads/2013/05/valid-default-path.png" alt="valid-default-path"/><br>
This works as you would hopefully expect. When given a valid path, it&rsquo;s fine. When allowed to use a valid default, it&rsquo;s fine. When given an invalid path, it barfs in the ValidateScript. Now look at the next example - which more closely approximates what people have been seeing in their Scripting Games scripts:<br><a href="https://powershell.org/wp-content/uploads/2013/05/invalid-default-path.png"><img src="https://powershell.org/wp-content/uploads/2013/05/invalid-default-path.png" alt="invalid-default-path"/><br>
In the Games, you were given a default path that<em>wasn&rsquo;t valid on your computer.</em> So folks allowed their script to run with that default, and got errors, and were annoyed that ValidateScript() didn&rsquo;t catch the problem.<br>
It never will.<br>
When you run a command, PowerShell goes through a process called parameter binding, wherein it attaches values to parameters and runs any declarative validation - like ValidateScript(). That validation will<em>always</em> catch invalid incoming data that&rsquo;s been manually specified or sent in via the pipeline (for parameters that accept pipeline input). Because my -Path parameter wasn&rsquo;t declared as mandatory, the validation routine will let me run the script and not specify -path.<br><em>Then</em> the shell actually<em>runs</em> my code - and<em>that&rsquo;s</em> when it assigns the default value to $path if one wasn&rsquo;t specified on -path. Validation is over by this point, so an invalid default value will sneak by. The assumption by the shell is that<em>you&rsquo;re</em> providing the default value, so<em>you&rsquo;re</em> smart enough to provide a valid one. If you don&rsquo;t, it&rsquo;s your problem.<br>
So do you just add a second, in-code check for the parameter? I&rsquo;d still say no. I really dislike redundancy. If you know, because of your situation, that you can&rsquo;t rely on ValidateScript(), then don&rsquo;t use it at all - one check should suffice, and if it needs to be in-code instead of declarative, that&rsquo;s fine. What&rsquo;d be nice is if there was a declarative way of specifying a default, like<strong>[Default(&lsquo;whatever&rsquo;)]</strong> that ran before the validation checks, but such a thing doesn&rsquo;t exist. Frankly, you could probably argue that if you can&rsquo;t guarantee the validity of a default, then you shouldn&rsquo;t provide one - and I&rsquo;d probably buy into that argument, and subscribe to your newsletter.<br>
In this case, the problem is entirely artificial. The default path value given to you in the Games scenario<em>is</em> valid<em>in the context of the Games;</em> it&rsquo;s just when you test it on<em>your</em> system,<em>outside</em> that context, that a problem crops up.<br>
Hopefully this helps explain how the ValidateXXX() attributes work, and how they interact with other features, like a default value.<br><em>Now</em> explain why this will never assign C:\ as a default value:<br><strong>[Parameter(Mandatory=$True)][string]$path = &lsquo;c:'</strong></p>
]]></content:encoded></item><item><title>Tobias' Judge Notes</title><link>https://powershell.org/articles/2013-05-01-tobias-judge-notes/</link><guid>https://powershell.org/articles/2013-05-01-tobias-judge-notes/</guid><pubDate>Wed, 01 May 2013 13:33:45 +0000</pubDate><description>&lt;p&gt;Tobias Weltner offers some &amp;ldquo;don&amp;rsquo;ts&amp;rdquo; from his review of Event 1 entries: &lt;a href="http://www.powertheshell.com/scripting-games-advanced-1/"&gt;http://www.powertheshell.com/scripting-games-advanced-1/&lt;/a&gt;&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Tobias Weltner offers some &ldquo;don&rsquo;ts&rdquo; from his review of Event 1 entries:<a href="http://www.powertheshell.com/scripting-games-advanced-1/">http://www.powertheshell.com/scripting-games-advanced-1/</a></p>
]]></content:encoded></item></channel></rss>