Skip to main content
PowerShell

PowerShell : Creating your own modules

By February 17, 2014September 12th, 2022No Comments

It is possible to have all of the functions, aliases and variables you need to load from your profile in PowerShell but you may well end up with 3 to 400 lines of code that is loaded each time the console opens but is rarely used. To remedy this we could make use of PowerShell Modules. These do not have to be complex or difficult, we will start with very basic functionality, but then as our scripting improves we can begin to add more complexity to the modules. A module can load aliases and variabl;es for you and additionally we can create functions to use when required. these function may or may not take input parameters and we are not restricted to home may we may load in a single module.

The module will have a .PSM1 extension is is normally created in a folder with the same name of the module, just omitting the extension. Modules can be loaded from their full path or just by their name if the directory holding the module is created in your documents directory and WindowsPowerShellModuleNameModuleName.PSM1

Get-Module
Get-Module -ListAvailable
Import-Module c:usersandrewtest.psm1
Import-Module ModuleName