Scripting Games: July 2015

I'm a bit late doing this, but I made my entry to the Scripting Games this morning and thought I'd share it. 

Here are the rules for this month's 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.

Check out the original source for a better look at the formatting they're looking for on their output.

Here's my solution:

Some things I want to make note of here:

  • The sample output that we were given to imitate was also a single line, meaning that the output they're looking for is flattened. I've done my best to imitate that by converting the output to a string, then replacing the literal linebreaks with three tab characters, which appears to be close to what they had; I also trimmed the start so that it wouldn't have extra space at the beginning, which wasn't shown in the sample output.
  • If the intention was NOT to imitate the flattened string output (though I suspect it was), you can get that by removing everything from the last pipe character on, and the opening parentheses after the Param block.
  • I used Param here, which means it will work fine if you just paste it on the command line and change the value of $Comp, or if you save it as a ps1 file and use -Comp to pass it the computer names you want to use.

I'm not going to go in to a great deal more detail on this one at this time, though I might come back later if I have the time.

For those who don't know about the Scripting Games and their new monthly format, check it out here: