People here at PDQ.com know how much I love Futurama, and Zapp Brannigan quotes are some of my favorites.
Since I can never decide on my favorite quote, it only seemed natural to throw together a quick PowerShell function to get a random Zapp quote any time that I wanted.
I’ve had a few people ask me about it, so I figured that I’d throw a blog together.(drum roll please) Enter PowerShell!
In the game of chess, you can never let your adversary see your pieces
Zapp Brannigan, Futurama
In order to randomly choose from a set of items, we are going to make use of the Get-Random cmdlet.Get-Random will pick a random number or a random object from a collection of objects.By default, Get-Random will pick a random number between 0 and the maximum 32-bit integer value (2,147,483,647).
You can also define a minimum and maximum value to randomly choose from. The maximum value, however, will never be chosen so you’ll need to pick a value that’s 1 higher than the range you’re expecting. For example, if you want to select a number between 1-10, you would do the following:
Can’t decide on a delicious bourbon to drink? Let’s use an array! You can pipe the array in or you can specify it as the input object.
Now onto the fun stuff!
Zapp Brannigan quotes
Pick your favorite quotes and put them in an array. Then, pipe that array to Get-Random and voila! You’re done!
This is not an exhaustive list of awesome Zapp quotes, but it’s enough to get anyone started! Now you can enjoy one of your Zapp quotes anytime you use the function, Get-ZappQuote. Amazing!
Creating a PDQ Inventory tool with your PowerShell Function
I’ve even taken this a step further and threw it together as a tool in PDQ Inventory. I dot source my Get-ZappQuote script and then run the function. Here’s how I create my tool (complete with my default tool description in the output).
Open PDQ Inventory and click on Tools in the tree.
On the Tools Menu tab, click New > Tool.
In the Tool window, in addition to adding your script, ensure the following is selected: PowerShell, Leave Shell Open, and System Tool (no selected computer needed).
Here is how I run my tool from within PDQ Inventory. It doesn’t require that a machine is selected, so I can run the tool from any screen. Simply click Tools > Tool name and away it runs.
The practical applications of Get-Random are pretty much endless. Anytime you find yourself unable to make a choice, consider throwing PowerShell at the problem! You, my friend have just created a PowerShell Magic 8-ball!
Kris was an employee at PDQ.