Field Note

Authoring PowerShell Script Modules

powershell module
Posted on Wednesday, October the 30th 2024
1 min read
  1. 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.
  2. 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 the Export-ModuleMember commandlet (e.g. Export-ModuleMember -Function MyFunction if you declared a function MyFunction)
  3. Import module members using Import-Module (you may specify -Verbose to see what is being imported)
friedrichkurz.me

© 2025 Friedrich Kurz

Privacy Policy