2015-July Scripting Games Puzzle

Scripting Games

Our July 2015 puzzler is designed to make you really think about the PowerShell parser. Normally, you can more or less ignore the parser, because if you're typing best-practice, long-form code (no aliases, spell out parameter names, etc), the parser deals really well with everything. But knowing how the parser works is useful, because when you get into tricky syntax, the parser can be harder to work with. So we're going to test the limits of the parser's patience - and your skills!


The Scripting Games have been re-imagined as a monthly puzzle. We publish puzzles the first Saturday of each month, along with solutions and commentary for the previous month's puzzle. You can find them all at https://powershell.org/category/announcements/scripting-games/. Many puzzles will include optional challenges, that you can use to really push your skills.

To participate, add your solution to a public Gist (http://gist.github.com; you'll need a free GitHub account, which all PowerShellers should have anyway). After creating your public Gist, just copy the URL from your browser window and paste it, by itself, as a comment of this post. Only post one entry per person. You are not allowed to come back and post corrected or improved versions. If you do, all of your posts will be ignored. However, remember that you can always go back and edit your Gist. We'll always pull the most recent one when we display it, so there's no need to post multiple entries if you want to make an edit.

Don't forget the main rules and purpose of these monthly puzzles, including the fact that you won't receive individual scoring or commentary on your entry.

User groups are encouraged to work together on the monthly puzzles. User group leaders should submit their group's best entry to Ed Wilson, the Scripting Guy, via e-mail, prior to the third Saturday of the month. On the last Saturday of the month, Ed will post his favorite, along with commentary and excerpts from noteworthy entries. The user group with the most "favorite" entries of the year will win a grand prize from PowerShell.org.

Our Puzzle

Write a one-liner that produces the following output (note that property values will be different from computer to computer; that’s fine). 

PSComputerName ServicePackMajorVersion Version  BIOSSerial                                -------------- ----------------------- -------  ----------                                win81                                0 6.3.9600 VMware-56 4d 09 1 71 dd a9 d0 e6 46 9f

By definition, a one-liner is a single, long command or pipeline that you type, hitting Enter only at the very end. If it wraps to more than one physical line as you’re typing, that’s OK. But, in order to really test your skill with the parser, try to make your one-liner as short as technically possible while still running correctly.



Try to use no more than one semicolon total in the entire one-liner

Try not to use ForEach-Object or one of its aliases

Write the command so that it could target multiple computers (no error handling needed) if desired

Want to go obscure? Feel free to use aliases and whatever other shortcuts you want to produce a teeny-tiny one-liner.

77 Responses to " 2015-July Scripting Games Puzzle "

  1. […] was 1AM in the morning I raced over to check out the first Puzzle. Mr Don Jones has posted it over here so please go have a read and give the puzzle a solid attempt before reading any […]

  2. All the comments here should have been hidden, just my opinion.

    • Don Jones says:

      That misses the entire point of the monthly puzzles, which is to be able to see how other people approach the problem. Keep in mind that there’s no scoring and no winner. Also keep in mind that you’re only supposed to post ONE entry.

  3. Stephen Owen says:

    I’m posting mine here but look forward to seeing everyone else’s as well!

  4. My try:
    $c=Read-Host ?;gwmi CIM_OperatingSystem -cn $c|select ps*,s*n,v*,@{n=’BIOSSerial’;e={$_.serialnumber}}

  5. happysysadm says:

    Minor correction for readability:

  6. selene v says:

    GWmi -Class win32_operatingsystem -computername “onecomputername”,”twocomputername” | ft -Property PSComputername,ServicePackMajorVersion,Version, @{Label=”BIOSSerial”; Expression={$_.serialnumber}}

  7. […] If you haven’t heard, PowerShell.org is taking the lead on organizing the PowerShell Scripting Games. There’s a new format that involves monthly puzzles. Here’s their post on July’s puzzle: https://powershell.org/2015/07/04/2015-july-scripting-games-puzzle/ […]

  8. https://gist.github.com/mtnielsen/9a3c249559bdcc9f022f
    Unfortunately neither of my two computers seem to have a BIOS serial number. Oh well.

  9. Chris Seiter says:

    https://github.com/cseiter/Scripting_Games/blob/master/July_2015 I found it quite funny when testing it my BIOS Serial number came up “To be entered by O.E.M”

  10. […] On 27th June the new format for the Scripting Games was announced on the Hey, Scripting Guy! blog. One week later, powershell.org published the first puzzle. […]

  11. Mukesh Kumar says:

    In Powershell V2, when i run gwmi win32_OperatingSystem | Select-Object @{Name=”PSComputerName”;Expression={$_.__SERVER}}
    the result is blank. But if i put this in a variable (like $a) : $a=gwmi win32_OperatingSystem | Select-Object @{Name=”PSComputerName”;Expression={$_.__SERVER}}
    , then $a.PSComputerName gives me the value.
    On V3, the command displays value. The difference i notice is PSComputerName is a NoteProperty in V2 while it is an aliasProperty in V3(introduced in V3 only).
    Can i make ” gwmi win32_OperatingSystem | Select-Object @{Name=”PSComputerName”;Expression={$_.__SERVER}} ” return value in V2 ?

  12. avsune says:

    Sorry for a delayed response.. I came to know about this quiz recently.

  13. […] Join us on Thursday, August 6th when June Blender will be conducting a hands on lab (in person!) called Working with Classes in PowerShell 5.0. To participate in the lab, bring a laptop (or VM) with PowerShell 5.0, but it’s not required! After that, we will review the results of the July Scripting games puzzle.  […]

  14. Don Walker says:

    Couldn’t resist a little user error control… must not be blank input.

  15. Mark Whitby says:

    I thought it might be helpful to dig into how I arrived at this, so I’ve written it up here

  16. […] The 2015 Scripting Games are upon us! […]

  17. […] how the 2015 Scripting Games have been re-imagined as a monthly puzzle with a July puzzle happening right now. Stay tuned for a celebrity post by Boe coming out at the end of the month where he will share his […]

  18. Ok, I missed the teeny-tiny bit of the brief. Perhaps this can be an example of how much you can get away with using parentheses and commas.
    This can all be entered on one line without pressing ENTER until the end. No semicolons, no foreach or aliases, and could target multiple computers (1-by-1).
    I’ll document my (long-winded) approach in a blog post, for now here’s the code:

  19. […] July puzzler wasn’t intended to break your brain – but it was intended to highlight an extremely […]

  20. That was fun…took about 15 minutes, and I managed to do it without any loops or semicolons.

  21. […] first puzzle called for a one-liner that produces the following […]

  22. […] learn more about this scripting games puzzle, see the “2015-July Scripting Games Puzzle” article on […]