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

More Fun with PowerShell Thrillers

Posted on November 20, 2018

Last week I posted a Friday Fun article about using PowerShell to create a synopsis for a hypothetical thriller novel. Naturally I wasn't satisfied to leave it at that. Don't get me wrong, it was a good start. But I needed to take the next logical step. I had a script, but that meant having to type the full path to the script. It would have been better if I had a function. I already had an internal function, which would need to remain hidden. Plus all of the content was embedded in the script. It would be better to turn this into a module.

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!

It was pretty easy to begin. I renamed the initial script file with a psm1 file extension. I wrapped the main code into a function and moved the internal, helper function outside of the main function. The only other thing I need to do was use Export-ModuleMember to make the function visible.

Export-ModuleMember -Function New-Thriller

Now I could import the module and have a command to run. The data was still internal which meant that if I wanted to add new titles or names to the lists I had to modify the file. I decided the easiest solution was to move the data to an external json file. This way I could import the file as an object.

image

This also meant I could use the data in other ways, such as creating a command to get one or more titles.

PS C:\> Get-PSThrillerTitle -Count 3
The Drive-In
Thunderstruck
No Yesterdays

Or create a characters object.

PS C:\> Get-PSThrillerCharacters

Hero             : Jim Shorts
FormerOccupation : Marine
TheWoman         : Mary Ann
HerStory         : a cocktail waitress
Villain          : The Shadow

I've gone through the json file and added even more potential values. I also added some fake testimonials from other authors.

image

Along the way, I renamed the noun in my commands to PSThriller and created a manifest. I also used the Platyps module to create help for the exported commands.

image

The primary purpose for all of this work is education. I want you to be able to see how a module goes together. I want you to know how you can have a mix of private and public functions. I want you to see how you can integrate a data source into your commands.

I don't plan on publishing this to the PowerShell Gallery since it isn't really a practical module. But I hope you will go the project's GitHub repo at https://github.com/jdhitsolutions/PSThriller and check out the code. There is a release zip file you can download if you wish. The README.md file has additional information.

Have fun and watch your six!


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

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