Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Friday Fun – New Thriller

Posted on January 14, 2011March 28, 2011

I read a lot of thrillers by authors like James Rollins, Jeff Long, Douglas Preston and Lincoln Childs. Certainly not high-brow literature, but generally well written and often a lot of fun. Of course with any fiction genre, there are certain thematic paradigms that must be followed, almost as if by recipe. Thus was born a short PowerShell script to create a new thriller synopsis. Even if you don't plan on writing your own thriller, you might pick up a PowerShell technique or two.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

The main part of the script is a string replacement using the -f operator. One the left side of the expression you have a series of place holders. On the right side of the -f operator is a comma separated list of values. Here's an example. See how the right side values are plugged into the left side place holders.
[cc lang="PowerShell"]
PS S:\> $d=dir *.ps1PS S:\> "Found {0} PowerShell scripts with a total size of {1} in {2}." -f $d.count,($d | Measure-object length -sum).sum,$d[0].directoryname
Found 721 PowerShell scripts with a total size of 2388840 in C:\scripts.
[/cc]
Enclose expressions you want to evaluate in parentheses. Armed with this technique, creating a new thriller synopsis is pretty easy.
[cc lang="PowerShell"]
$Title="The Omega Plan","Deep Rising","The Last Man Standing","Running on Empty","Paradise City","THe Hidden Door"
$Name="Jack Frost","Paul Bunyan","Roy Biv","Art Deco","Jim Shorts"
$first=($name | Get-Random).Split()[0]
$Former="Navy SEAL","Army Ranger","NASA shuttle astronaut","Green Beret","NSA analyst","Secret Service agent","CIA agent","IT administrator","Delta Team commander"
$villian="The Society","The Guild","SPECTRE","The Brotherhood","The Guardians of the Rose","Google","Microsoft","The Illuminati"
$family="son","daughter","wife","mother","father","dog","hamster","sister","brother","twin" | Get-Random
$tragedy="the tragic loss of his $family","the nightmares of war","a missing library book","a toothache","a fear off flying"
$mystery="Clippy","Macchu Pichu","meatloaf","Atlantis","the missing Mayans","alien abductions","Easter Island","chocolate covered bacon","the last pharoah"
$backdrop="ancient Egypt","ancient Greece","Istanbul","Omaha",",Singapore","Antarctica","the Hindu Kush","the Amazon rain forest"

"""{0}"" finds {1} in the middle of an extraordinary adventure that will push him
beyond the breaking point. A former {2}, {3} finds himself trapped in the middle of
a series of catastrophic events unleashed by {4} that threaten not only his sanity
but the very fabric of society. Haunted by {5}, {3} must overcome a complex and
diabolic plot surrounding the mystery of {6}. Set amidst the exotic backdrop of
{7}, {3} will make a discovery that will change his world, and ours, forever. But
can he do it before time runs out?" -f ($title | get-random),($name | Get-Random),($former | Get-Random),$first,($villian | Get-Random),($tragedy | Get-Random),($mystery | Get-Random),($backdrop | Get-Random)
[/cc]

The first part of the script defines variable arrays for the different required thriller elements. I use Get-Random to pick one choice from each element and then plug that value into the -f operator expression. Here's a sample result.
[cc lang="PowerShell"]
PS S:\> .\New-Thriller.ps1
"The Last Man Standing" finds Jack Frost in the middle of an extraordinary adventure that will push him
beyond the breaking point. A former NASA shuttle astronaut, Paul finds himself trapped in the middle of
a series of catastrophic events unleashed by The Guild that threaten not only his sanity
but the very fabric of society. Haunted by the tragic loss of his son, Paul must overcome a complex and
diabolic plot surrounding the mystery of Atlantis. Set amidst the exotic backdrop of
the Amazon rain forest, Paul will make a discovery that will change his world, and ours, forever. But
can he do it before time runs out?
[/cc]
Hmmm...that sounds interesting.

Download New-Thriller


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

4 thoughts on “Friday Fun – New Thriller”

  1. Pingback: Tweets that mention Friday Fun – New Thriller | The Lonely Administrator -- Topsy.com
  2. Tome Tanasovski says:
    January 19, 2011 at 11:09 pm

    PowerShell makes a great madlibs machine!

    -f is one of my favorite tools. When I use it with doublequotes “” I use single quotes to enclose it rather than the double doublequotes, i.e.,

    '"{0}" finds {1}'

    1. Tome Tanasovski says:
      January 20, 2011 at 2:08 am

      I went a little overboard: I wrote the madlibs script! Completely inspired by your article!

  3. Pingback: PowerShell Mad Libs! What Else Could We Possibly Need? « Tome's Land of IT

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d