Consuming packaged PowerShell modules in steps

We have a series of PowerShell functions (cmdlets), wrapped up into a PowerShell module (.psm1 / .psd1). These are stored in our external NuGet package library (feed). We want to call these functions in steps.

The problem is that the “Run a Script” step is design to do just that, as opposed to a PowerShell module.

Available options

  1. If I set the “Script Source” to Inline source code it disables the options to select the feed and package ID.
  2. If I set the “Script Source” to Script file inside a package it wants a script file name i.e. Get-Something.ps1

Option 1 is how I have done it in VSTS, calling Import-Module -Name {path_to_psm1} -Force, however I can’t find a way to reference the package. There don’t seem to be any variables available.

I’d call my cmdlet something like this:

Import-Module -Name #{Octopus.Action['PackageId]} -Force

Get-SomeCmdlet -SomeParam1 #{Var1} -AnotherParam #{Var2}

Option 2 - I can’t create a PS1 file that essential does the pseudo example above as this will break the module. Every time the module is imported / loaded, the PS1 would execute. There is a way around it, but it breaks the module standard and would get messy. I could try creating a separate package for “executable” scripts, and add an additional package but that seems overkill.

It seems to me that we need a third option / new step template “Import PowerShell Module and run cmdlets”.

In the absence of such a step template, can anyone suggest a way to achieve this either with the default steps, or writing our own step template?

We only deploy PaaS, so we have no Tentacles.


Clearly, I am blind:

I can then use:

$WorkFolder = $OctopusParameters['Octopus.Action.Package[_Ful_name_of_package].ExtractedPath']

Write-Host "Install location: $WorkFolder"

$ModulePath = Join-Path $WorkFolder "MyModule\MyModule.psm1"

Import-Module -Name $ModulePath -Force -Verbose -Passthru

A link to the hidden-from-google page with the magic:

T, A.

Hi @Tex,

Thanks for getting in touch! I’m glad to hear that you figured this out. :slight_smile:

If you have any further questions here, or run into any issues, please don’t hesitate to let us know.

Best regards,

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.