HTH   Hope This HelpsAnchoriTunesSpotifyOvercastTwitterMastodonTwitchRSSReddit

PowerShell Modules

Author: Steve

Making PowerShell Modules is fairly easy. To oversimplify it: They are effectively just files containing piles and piles of functions. You can technically even have a module containing just one function.

Start out by firing up your IDE of choice (I prefer Visual Studio Code, as does Jeff Snover). Make a new file and start pasting in your functions. Don't paste in excess code like function calls or other extracurriculars, we don't need that here.

Once you've pasted them all in, hit File->Save As. Save your file as "MyModuleName.psm1" inside a folder named the same (Example: MyModuleName\MyModuleName.psm1).

Now that you've saved your module inside a folder, you are ready to move it into a PowerShell Modules directory. You have two options:

1. Move it into the User Modules directory.
    a. Windows PowerShell is "C:\Users\<username>\Documents\WindowsPowerShell\Modules"
    b. PowerShell Core is "C:\Users\<username>\Documents\PowerShell\Modules"
    c. Mac is "~/.local/share/powershell/Modules"
2. Move it into the System Modules directory.
    a. Windows PowerShell is "C:\Program Files\WindowsPowerShell\Modules"
    b. PowerShell Core is "C:\Program Files\PowerShell\7\Modules"
    c. Mac is "/usr/local/share/powershell/Modules"

Once saved, you can fire up a PowerShell Window and try "import-module MyModuleName" and see if it imports.

If you saved it into your user directory, it's only available for you. If you saved it for all users, all users will be able to import the module and use the functions.

Check out this link for an example.

Hope This Helps!