PS: Moving To Modules Pt. 2

Description:

This is a continuation post of Moving to Modules I posted earlier. Main thing, I just wanted to go over design in this post. Here is a typical module:

A good way to see this is to download one of my Modules off Github. From here you can see the folder structure and how I use the modules in a portable fashion (explained below).

To Resolve:

1a. So the modules can be named whatever you want. The first thing you do is create a guid for your template so it can be unique in case you ever post it online. You can use online sites like GUID Generator or just Powershell: $GUID = [guid]::NewGuid().ToString() |Clip.exe

2. Next you can create and edit your template.psd1 file:

3. Next you want to create and edit your template.psm1 file. The good thing about this is that it is the same for any module you create:

4. Now you create your three folders:
a. Logs – You don’t do anything with this, just create it.
b. Private – This is where private functions go, this is where my helpers.psm1 file lives with helper functions. These will not be exported by the module.
c. Public – This is where all your .ps1 scripts go. If you do like me, you will make them all advanced functions and the way users will use them is:

c1. They will import your module and then just call the function that way – preferred.
c2. For one offs, they can navigate to your Public folder in powershell or Windows Explorer and dot source your script and then call the function from within it.

5. Lastly, in the Public folder, you create functions that use a setup like in my current Template script.


2018-09-22: Just wanted to add that setting them up this way allows me to pull from Github pretty easily: