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!
Instructions
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.
Challenges:
• 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.
[…] over to https://powershell.org/2015/07/04/2015-july-scripting-games-puzzle/ for our inaugural Scripting Games […]
https://gist.github.com/repentster/015d575a944ab65311b6
https://gist.github.com/artisticcheese/28094a3eb4b36c07e464#file-gistfile1-ps1
https://gist.github.com/bundyfx/a8cfe0856ee8d2093002
https://gist.github.com/bundyfx/9afcd8828103a7f62160
[…] 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 […]
https://gist.github.com/Windos/de90d1fa84d6d9b85626
Edit, had mine set to secret gist.
https://gist.github.com/bundyfx/5b8ac3a16d807b40cda4
All the comments here should have been hidden, just my opinion.
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.
I’m posting mine here but look forward to seeing everyone else’s as well!
https://gist.github.com/1RedOne/e2a89f1a2ec5413d2c37
My try:
$c=Read-Host ?;gwmi CIM_OperatingSystem -cn $c|select ps*,s*n,v*,@{n=’BIOSSerial’;e={$_.serialnumber}}
gwmi CIM_OperatingSystem -cn (read-host ?)|select psc*,s*j*,v*,@{n=’BIOSSerial’;e={$_.serialnumber}}|ft
Forgot the gist:
https://gist.github.com/1bcee6040f560dfca997.git
I guess I don’t know how to properly paste a Gist link:
https://gist.github.com/MickyBalladelli/1bcee6040f560dfca997
Better support for multiple remote systems:
https://gist.github.com/MickyBalladelli/1bcee6040f560dfca997
Fine-tuned version
https://gist.github.com/MickyBalladelli/1bcee6040f560dfca997
https://gist.github.com/mattmcnabb/94bff1bea1fc7bfd5cbb
It s Ready..WALAAHH…!!!
https://gist.github.com/kvprasoon/1486c5fea136d78b52bc
https://gist.github.com/kvprasoon/1486c5fea136d78b52bc
GotOne More!
https://gist.github.com/kvprasoon/2ace692398c2136344b5
https://gist.github.com/the-IT-guy/38e85bd1524830549d01
https://gist.github.com/MVKozlov/336be112ea37f82d77d7
https://github.com/happysysadm/scriptinggamesjuly2015/blob/21ef0fbfb6025343e9a3e2468c39a01361040ae9/wmiclasses.ps1
https://gist.github.com/happysysadm/b79062a61a3c8419c48e
Minor correction for readability:
https://gist.github.com/happysysadm/30fc31865c7c36916e79
First (and maybe only) attempt
https://gist.github.com/csandfeld/5bbaf3d6064235bdeada
https://gist.github.com/JohnBravo/7ececade3eb0ee965bb2#file-scriptinggames2015-july
GWmi -Class win32_operatingsystem -computername “onecomputername”,”twocomputername” | ft -Property PSComputername,ServicePackMajorVersion,Version, @{Label=”BIOSSerial”; Expression={$_.serialnumber}}
https://gist.github.com/Mukesh05/0fba9c673bacf36bfeb3
[…] 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/ […]
https://gist.github.com/mtnielsen/9a3c249559bdcc9f022f
Unfortunately neither of my two computers seem to have a BIOS serial number. Oh well.
Turns out one of them did have a serial number. The code just didn’t do what I wanted it to.
https://github.com/SubuUbus/July-Powershell-Scripting-Games/blob/master/puzzle.ps1
Embed? 🙁 https://raw.githubusercontent.com/SubuUbus/July-Powershell-Scripting-Games/master/puzzle.ps1
https://gist.github.com/ThmsRynr/ccbac1b3464ad05e7224
And a blog post explaining it, just for fun: http://www.workingsysadmin.com/my-july-2015-scripting-puzzle-solution/
https://gist.github.com/subodhuniyal/bbbeac35c67931f8e9bb
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”
[…] 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. […]
WAS CURIOS TO MAKE THIS WORK ON V2 AS 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 ?
https://gist.github.com/sixfivemil/027234865d112837f956
https://gist.github.com/treestryder/fb335844be5e88a4be81
Thanks for another round of games!
https://gist.github.com/poshbrs/a73b61a608d7733f4456
https://gist.github.com/jeepasaurus/7c7c44e8cb12e960622a
https://gist.github.com/jimmehc/8d450a3792ce5b5141ef#file-gistfile1-txt
? It didn’t embed. Maybe without the #file…
https://gist.github.com/jimmehc/8d450a3792ce5b5141ef
https://gist.github.com/EsOsO/1226f4e89c4524a18325
https://gist.github.com/paalbra/0609af6a8fa27c8c91bd
Sorry for a delayed response.. I came to know about this quiz recently.
https://gist.github.com/avsune/56145bd22dc51d85a5d9
https://gist.github.com/jeffbuenting/d9db3c8a425dda1a12ba
https://gist.github.com/corydwood/3c4d13fe6e2106da9a84
[…] 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. […]
Couldn’t resist a little user error control… must not be blank input.
https://gist.github.com/8bc8eac35fce85092ddf.git
https://gist.github.com/EngineeringDon/8bc8eac35fce85092ddf
https://gist.github.com/chipfat/52ab783ca01dbba7c41e
I thought it might be helpful to dig into how I arrived at this, so I’ve written it up here
http://markw.me/2015/07/15/PowerShell-Scripting-Games-July-2015/
https://gist.github.com/powershelleanpeoplesfront/ca179463913129dd49d8
https://github.com/Centric-PowerShell-Minions/July/blob/master/Answer_July
[…] The 2015 Scripting Games are upon us! […]
https://gist.github.com/stestino/fb3848f012ee07e87cfb
https://gist.github.com/414b3ff9c5195992ec05.git
https://gist.github.com/414b3ff9c5195992ec05
[…] 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 […]
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:
https://gist.github.com/520f878c80148c918fa9.git
Let’s try that with the correct link.
https://gist.github.com/pandiculator/520f878c80148c918fa9#file-sg_puzzle1-ps1
[…] July puzzler wasn’t intended to break your brain – but it was intended to highlight an extremely […]
That was fun…took about 15 minutes, and I managed to do it without any loops or semicolons.
https://gist.github.com/poshcodebear/a66bed5b18c6642385de
Okay, one semicolon…it’s kind of required when doing a script property.
[…] https://powershell.org/2015/07/04/2015-july-scripting-games-puzzle/ […]
[…] first puzzle called for a one-liner that produces the following […]
[…] learn more about this scripting games puzzle, see the “2015-July Scripting Games Puzzle” article on […]