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.
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
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}'
I went a little overboard: I wrote the madlibs script! Completely inspired by your article!