Posted in Module, Powershell

Checking your installed modules versions

Okay in a bit of a rush and should have posted this one some time ago. In a rush because I  was led along the lines ( thanks Bret Miller ) of using a GitHub Gist to better display (and share) code that I include in posts…

Yes this is very version 1. It was simply a utility I started writing for my own use. Then I found some folks who were running old versions of certain PSGallery installed modules like msonline, ImportExcel or the plethora of Azure Modules. Admittedly I watch Twitter and RSS feeds all day for PowerShell so I was rarely surprised by the results.

The code is a PowerShell function so it can be easily deployed. I recommend placing it in your profile (old school I guess but I still prefer profile.ps1) so you can call it in any PowerShell session.

Recently, well after I  slapped a similar function together for auditing my chocolatey installed packages, I started to look at the next version. After making notes and  beyond  bad code I saw a few things so I am starting a new project to improve it. One quick upgrade will be making the display smart to show the primary module (for example VMware.PowerCLI and not all the sub modules that are part of PowerCLI) only. So now I am looking at creating the project (and learn how to use github projects). My next version will not display to the console with any great expertise like @jaykull but here is a rough version:

mod-list-v2

Posted in Module, Plaster, Powershell

Plaster Baby Steps

Just a quick note… started to get addicted to plaster. One other thing I learned but not fully. I wanted to include the PowerShell Version to the plaster process. I made changes and the template started failing. It would appear there is some case sensitivity:

powerShellVersion='$PLASTER_PARAM_ModulePSVer'
The “p” in powerShellVersion appears to be lowercase only. I have to figure out the parameter names and case sensitivity. I found this by trial and error but I need to get more fluent with it.
Posted in Module, Plaster, Powershell

PowerShell Plaster Baby Steps

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  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="&amp;Yes" help="Creates a en-US folder within the module root" value="Yes" />
                        <choice label="&amp;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.