I have created modules, normally just for a demo showing how easy it would be to distribute PowerShell. They were simply a script I renamed to psm1 or a psm1 I created and threw some functions in it.
With the current role in, I see a greater need for a few modules. I could go with a bunch of functions in a script, or load scripts during runtime of my main script. I do not want to clutter my script with a large number of functions or even a few lines like:
. .\script1.ps1 . .\script2.ps1
Now I have to admit I have use Sapien’s PowerShell Studio to create a few modules. While I love the product I do not have access to it. That said it creates basic/static module files.
I saw the plaster module, read a few articles about it and at first my response was “meh” but hey it is prompting me for some interesting items so I must be missing something. I spent a day or two but just couldn’t figure something out like adding the Company Name at build time.
I was using Twitter to follow the news coming from the 2018 PowerShell summit. A post announced that there was going to be a presentation regarding Plaster. I liked the post and mentioned that I can’t wait to see the presentation when it was posted.
Two days later I received a link to the presentation. Major thanks to @barbariankb for facilitating @rjpleau sending me a link to the presentation materials which can be found on github here.
Using this as a practical reference I was able to figure out what I was doing wrong with just get the company name as a runtime option. I know, nothing monumental but I write my own modules but at work I want to ensure I record my employers company name.
Sorry for the formatting of the XML is not great. Basically I copied an existing template (finding that folder is not easy (start looking in $env:userprofile either .vscode or .vscode-insiders then find the powershell module, then modules folder then plaster and then the templates folder). I copied the NewPowerShellScriptModule then renamed it. Then I edited the plastermanifest.xml to what you see below.
<?xml version="1.0" encoding="utf-8"?> <plasterManifest schemaVersion="1.1" templateType="Project" xmlns="http://www.microsoft.com/schemas/PowerShell/Plaster/v1"> <metadata> <name>JJK</name> <id>dd02bf66-9960-4014-a6fc-f09d5387c189</id> <version>1.0.0</version> <title>JJK Module Template</title> <description>Customized Manifest for creating Modules</description> <author>Kavanagh</author> <tags>Automation</tags> </metadata> <parameters> <parameter name="ModuleFullName" type="text" prompt="Module author's name" /> <parameter name="ModuleName" type="text" prompt="Name of your module" /> <parameter name="ModuleDesc" type="text" prompt="Brief description on this module" /> <parameter name="Version" type="text" prompt="Initial module version" default="0.0.1" /> <parameter name="ModuleCompanyName" type="text" prompt="Company name" default='N/A' /> <parameter name="ModuleScripts" type="choice" prompt="Create a scripts folder for non function scripts?" default='1'> <choice label="&Yes" help="Creates a en-US folder within the module root" value="Yes" /> <choice label="&No" help="Does not create a en-US folder within the module root" value="No" /> </parameter> </parameters> <content> <message> Scaffolding your PowerShell Module... </message> <newModuleManifest destination='${PLASTER_PARAM_ModuleName}.psd1' author = '$PLASTER_PARAM_ModuleFullName' moduleVersion='$PLASTER_PARAM_Version' rootModule='${PLASTER_PARAM_ModuleName}.psm1' companyName='$PLASTER_PARAM_ModuleCompanyName' encoding='UTF8-NoBOM' openInEditor="true"/> <file source='Module.psm1' destination='${PLASTER_PARAM_ModuleName}.psm1' openInEditor="true"/> <message>Your new PowerShell module project '$PLASTER_PARAM_ModuleName' has been created.</message> </content> </plasterManifest>
What I learned, and some of this is just take the example and following naming convenstions, in order to get something like a company name value in the resulting psd1 you have to create a parameter value and then include it in the newModuleManifest destination section To call the parameter which in this example is ModuleCompanyName you use $PLASTER_PARAM_ModuleCompanyName.
Cut to the end, in my resulting module’s psd1 you will find:
# Company or vendor of this module CompanyName = 'KavanaghTech'
Which is the value I entered when I started the invoke-plaster (even easier in VSCode as it is simply availabe in the command palette) using my new template and during the initial process that is the value I entered for the Company Name.
Sorry for the rambling but I just wanted to share what was a major frustration for me. I also wanted to share the greatness that is the PowerShell community.