How to Cheat at Sporcle

By now we hope you've had the chance to try your hand at our initial contribution to Sporcle, the online site for "mentally stimulating diversions." If you managed to solve the puzzle, all we can say is this: Congratulations on a job well done! But what if you weren't able to solve the puzzle? What then?

Well, no doubt your mom would say something like, "Well, if you want to succeed at something you just need to try harder." And, to be perfectly honest, we tend to agree with mom on this one … well, except for the part about "trying harder," of course. After all, trying harder is, well, hard. Isn't there an easier way to solve this puzzle? Some way, like, say, cheating ….

Fortunately for all of us (or at least for those of us who don't want to try harder), it turns out that it is possible to cheat at the Lync Server Sporcle puzzle. If you haven't had a chance to glance at the puzzle just yet, the whole thing looks a lot like this:

See the letters listed in the First Letter column? As it turns out, there's at least one Lync Server PowerShell verb that starts with each of the letters that appear in that First Letter column. For example, you see the letter D listed under First Letter. Why? Because there's at least one Lync Server verb that starts with the letter D. So how come you don't see the letter Z listed anywhere? You got: because there aren’t any Lync Server verbs that start with the letter Z. In order to solve the puzzle you just have to start typing in verbs; if you get one correct that verb will be put in the appropriate spot:

OK, so all we need to do is start typing in verbs, huh? Well, we know that there's at least one verb that starts with the letter A. OK, let's see: Abrogate? Ascertain? Ascend?

Hmmm, this isn't as easy as it looks …. In fact, it would be a lot easier if I didn't have to think about this, but instead already had a list of the answers sitting right in front of me.

Apparently we were thinking the same thing:

$letters = "A","B","C","D","E","F","G","H","I","J", `

    "K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"

foreach ($x in $letters)

    {

        $verbs = Get-Command -Module Lync |

            Where-Object {$_.Verb -like "$x*"} | Select-Object Verb

        $count = ($verbs | Measure-Object).Count

        if ($count -ne 0)

            {

                $verbs | Get-Random -Count 1

            }

    }

The preceding script is designed to help you solve the Lync PowerShell Verbs puzzle. How does it do that? Well to begin with, the first line in the script creates an array named $letters; as the name implies, this array contains each of the 26 letters found in the English alphabet.

After we create the array, we set up a foreach loop that loops through each item in that array; that is, through each letter in the alphabet. Inside the foreach loop, the first thing we do is run this command:

$verbs = Get-Command -Module Lync | Where-Object {$_.Verb -like "$x*"} | Select-Object Verb

What we're doing here is using the Get-Command cmdlet to retrieve a collection of all the Lync Server cmdlets (the Module parameter enables us to limit the retrieved data to just the Lync Server cmdlets). That collection is then piped to the Where-Object cmdlet, which picks out only those cmdlets where the Verb property begins with a specific letter. Which specific letter? Well, as we noted, the foreach loop is iterating through all the items stored in the array $letters. That means that, the first time through the loop, the loop variable $x is set to the value of the first item in the array: A. As a result, the first time we run through the loop we'll be looking for Lync Server verbs that start with the letter A. The second time we run through the loop, we'll be looking for Lync Server verbs that start with the letter B. Etc., etc.

In other words, the first time we run through the loop we'll grab information for all the Lync Server cmdlets whose Verb starts with the letter A. We then pipe that data to the Select-Object cmdlet, which extracts just the Verb values from that huge mass of data.

Note. Do we really need to do that? No, not really. However, Get-Command does return a lot of information about each cmdlet: Verb; Noun; DLL; Parameters; ImplementingType; etc. Because we care about only the Verb we decided to make things easier for everyone by getting rid of everything that isn't a Verb.

OK, let's pretend that Abrogate, Ascertain, and Ascend really are Lync Server PowerShell verbs. In that case, the variable $verbs will contain three items:

· Abrogate

· Ascertain

· Ascend

Note. If there’s more than one cmdlet that begins with the same verb, you’ll get multiple instances of that verb. For example, if there were cmdlets named Ascertain-CsDialPlan and Ascertain-CsVoiceNormalizationRule, your list would look like this:

Abrogate

Ascertain

Ascertain

Ascend

For the purposes of this script it doesn’t matter, we’re just going to randomly pick one anyway. But if you’d like to get only one instance of each verb, add the –Unique parameter to the end of your Select-Object command, like this:

$verbs = Get-Command -Module Lync | Where-Object {$_.Verb -like "$x*"} | Select-Object Verb –Unique

 

Got that? Good. Next, we use this line of code to count the number of items in the array $verbs:

$count = ($verbs | Measure-Object).Count

Why do we do that? Well, we already know that some letters don't have even one corresponding Verb; for example, there aren't any verbs that start with the letter X. Therefore, what we do with this line of code is count the number of verbs retrieved for the current letter. If the Count is 0, that means we don't have any verbs. Consequently, we skip that letter and go to the next item in the array. That's what will happen when we try the letter Q. There aren't any verbs that start with Q, which means that the Count will be 0. Which means, in turn, that we'll just drop the letter Q like a hot potato and then move on to the next letter in the array.

But what if the Count isn't 0? Well, that means that we have at least one verb that starts with the current letter. (For example, at least one verb that starts with the letter A.) If a letter has at least one corresponding verb we then run this command:

$verbs | Get-Random -Count 1

What's going on here? Here we're simply taking our collection of verbs (Abrogate, Ascertain, Ascend) and piping that collection to the Get-Random cmdlet. We're then asking Get-Random to randomly select one of those verbs (-Count 1) to display onscreen. As a result, we'll see something similar to this onscreen:

Ascertain

So what does that mean? That means that we can type Ascertain into the Sporcle puzzle and be sure of getting at least one answer correct. (We can’t, really. Ascertain was just an example. You’ll have to run the script to find the real answers.) After all, Ascertain won't show up onscreen unless it happens to be a valid Lync Server PowerShell verb.

See how much easier it is to cheat? Makes you wonder why people don't do it more often, doesn't it? Needless to say, we heartily condone, encourage, endorse, and otherwise recommend cheating whenever you think you can get away with it!

Note. Um, on the advice of our management, and in consideration of all the many young children out there who regularly read the Lync Server PowerShell blog, we do not condone, encourage, endorse, or otherwise recommend cheating of any kind.

Well, unless you know for sure that you'll never get caught. In that case ….

Anyway, after we've printed out a verb for the letter A (assuming that there is a verb for that letter) we then loop around and repeat the process for the letter B. By the time we're finished, we should see 14 verbs onscreen, 14 verbs that match up quite nicely with the answers needed to successfully solve the Lync PowerShell Verbs puzzle.

And here some of you thought that Windows PowerShell could never be put to any practical use. Now you know better!