- Create a file
MyModule.ps1
and store it in any of the locations defined in$Env:PSModulePath
(you can add custom locations by extending this environment variables) in a directory by the same name, i.e. if you store your module in/root/.local/share/powershell/Modules
, the full path must be/root/.local/share/powershell/Modules/MyModule/MyModule.ps1
or PowerShell won’t find the module file. - In your
MyModule.ps1
define functions (possibly with[CmdletBinding()]param(...)
declaration in the function body) and whatever you want to export; export module members with theExport-ModuleMember
commandlet (e.g.Export-ModuleMember -Function MyFunction
if you declared a functionMyFunction
) - Import module members using
Import-Module
(you may specify-Verbose
to see what is being imported)
Field Note
Authoring PowerShell Script Modules
powershell module

Posted on Wednesday, October the 30th 2024
1 min read