- Create a file
MyModule.ps1and 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.ps1or PowerShell won’t find the module file. - In your
MyModule.ps1define functions (possibly with[CmdletBinding()]param(...)declaration in the function body) and whatever you want to export; export module members with theExport-ModuleMembercommandlet (e.g.Export-ModuleMember -Function MyFunctionif you declared a functionMyFunction) - Import module members using
Import-Module(you may specify-Verboseto see what is being imported)
Field Note
Authoring PowerShell Script Modules
powershell module
Posted on Wednesday, October the 30th 2024
1 min read