My Solution: July 2015 PowerShell Scripting Games Puzzle

Last month, announced that the PowerShell Scripting Games had been re-imagined as a monthly puzzle and the first puzzle was published.

The instructions stated to use a PowerShell one-liner that produces the following output. No more than one semicolon should be used, do not use the ForEach-Object cmdlet or one of its aliases. The one-liner should be able to target more than one computer and feel free to go crazy with a really short one-liner with aliases and whatever else.

Although the instructions state that one semicolon can be used, this does not mean that two PowerShell commands separated by a semicolon could be used because that wouldn’t be a one-liner. A PowerShell one-liner is one continuous pipeline and not necessarily on one physical line.

Here’s my solution with full cmdlet and parameter names so you’ll be able to understand it easier. I don’t recommend using aliases or positional parameters in any code that you’re sharing even if it’s a one-liner. The use of full cmdlet and parameter names makes your code much easier to follow and more self-documenting.


My solution does require PowerShell version 4 or higher since I’m taking advantage of the PipelineVariable common parameter.

You may wonder why I’m using the older Get-WmiObject cmdlet instead of the Get-CimInstance cmdlet that was introduced in PowerShell version 3 since I’m using features that require PowerShell version 4?

If you’re using a client machine such as Windows 8.1 or Windows 10 with its default setting of not having PowerShell remoting enabled, the Get-CimInstance cmdlet will fail when the ComputerName parameter is specified and the local computer is targeted:


This is because Get-CimInstance uses the WSMAN protocol by default, although a CimSession could be created specifying the DCOM protocol with the New-CimSessionOption cmdlet or PowerShell remoting could be enabled on the local computer.

You may also run into similar issues with remote machines when using the Get-WmiObject cmdlet which communicates via DCOM which may be blocked on your network or via the firewall on remote machines.

My solution also works without issue against multiple computers and notice that although this command is on more than one physical line, it is indeed a PowerShell one-liner:


I decided to take my solution one step further. What if no semicolons were allowed? I also saw someone had posted that their computer didn’t have a “BIOSSerial” property. No one’s computer has one. You simply create a hash table with Select-Object or one of the Format cmdlets and rename an existing property. Here’s my solution with no semicolons:


I did carve up the command and use all of the aliases and shortcuts I could think of and I’ll post it here and let you be the judge of whether or not this command or the previous one is easier to follow:


There’s nothing wrong with using shortcuts such as aliases and positional parameters when working in the console as long as the code isn’t being saved or shared. It’s also beneficial to know what the aliases are since you’ll find others posting code that you’ll need to decrypt.

To learn more about this scripting games puzzle, see the “2015-July Scripting Games Puzzle” article on



  1. Tim Bolton

    Interesting that you had to use a period ” . ” after the ComputerName ” cn. ” alias when using the PipelineVariable ” -pv “

    • Mike F Robbins

      In that scenario the period or dot (.) is like an alias for the local computer name. I don’t recommend using it, but I used it with that one-liner to make it as short as possible.


Leave a Reply

%d bloggers like this: