Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell module - separate file for each cmdlet

I've been strugling with this for a while now. I intend to create new PowerShell module for my project. Aim is to package several custom cmdlets into standalone unit, which I could deploy to other machines via our Nexus repository (or via anything else).

Problem: Everywhere I look, I see tutorials packaging all PowerShell functions/cmdlets into single *.psm1 file. File is stored inside equally named directory, which actually represents module itself.

Question: Is there a way, how to separate each cmdlet/function into standalone file? If I have a module consisting of several cmdlets, it's not very convenient to put them all in single *.psm1 file.

Thanks Matthew

like image 733
Matthew Lowe Avatar asked Apr 15 '15 06:04

Matthew Lowe


1 Answers

Following up on @MatthewLowe - I've made my .psm1 a "one liner" as follows; this seems to work, provided that none of the scriptlets depend on one whose name is alphabetically after itself:

Get-ChildItem -Path $psScriptRoot\*.ps1 | ForEach-Object { . $_.fullname; Export-ModuleMember -Function ([IO.PATH]::GetFileNameWithoutExtension($_.fullname)) }

like image 147
Jeff Zeitlin Avatar answered Oct 12 '22 00:10

Jeff Zeitlin