The root module, a file with a psm1 extension, is given the same name as the module itself and will be nested directly under a folder that bears the module name.
When a module is installed into one of the folders in $env:PSModulePath, it may have the following structure:
Modules
| -- LocalMachine
| -- LocalMachine.psm1
The module can be imported immediately by passing the path to the LocalMachine folder to Import-Module. If the module content changes, the module should either be removed using Remove-Module, or the Force parameter should be used with Import-Module.
Environment variables modified using $env are not persistent; the change will disappear when PowerShell is closed. A temporary module path might be added to simplify testing while writing a module:
$env:PSMODULEPATH = 'C:Workspace;{0}' -f $env:PSMODULEPATH
Modules placed in C:Workspace may be discovered using Get-Module and Get-Command.
The LocalMachine.psm1 file includes all of the functions that make up the module. The content of LocalMachine.psm1 is shown in the following example; the body of the functions has been omitted in this snippet:
function Get-ComputerDescription { }
function Set-ComputerDescription { }
All of the functions in a module are made available to a user by default. The names of the functions will be shown when Get-Module is run, shown as follows:
PS> Get-Module LocalMachine -ListAvailable
Directory: C:Workspace
ModuleType Version Name PSEdition ExportedCommands
---------- ------- ---- --------- ----------------
Script 0.0 LocalMachine Desk {Get-ComputerDescription, Set-ComputerDescription}
The example shows that both of the functions are exported. If either function is run, the module will be automatically imported.