2015-July Scripting Games Puzzle

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.

Posted in:
About the Author

Don Jones

Profile photo of Don Jones

Don Jones is a Windows PowerShell MVP, author of several Windows PowerShell books (and other IT books), Co-founder and President/CEO of PowerShell.org, PowerShell columnist for Microsoft TechNet Magazine, PowerShell educator, and designer/author of several Windows PowerShell courses (including Microsoft's). Power to the shell!


    • 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.

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

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

  3. Unfortunately neither of my two computers seem to have a BIOS serial number. Oh well.


    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 ?

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

  6. 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: