Reputation: 149
I'm new with PowerShell and I've just started to create my own module.
I created the script & manifest files and placed them into the directory C:\Program Files\WindowsPowerShell\Modules\
who is one listed of the $env:PSModulePath
command.
I can import and remove the module as well but it's not recognized as an applet or command when I try to call one of the function.
I use the Import-Module command :
Import-Module MyModule
My script file is something like this :
function MyFunction() {}
Export-ModuleMember -Function *
And my manifest looks like this :
FunctionsToExport = '*'
Do I need to write all of the exported functions into the manifest ?
Thank you for your help.
Upvotes: 2
Views: 3682
Reputation: 1801
To export everything:
Module manifest (.psd1):
FunctionsToExport = '*'
Module script file (.psm1):
Export-ModuleMember -Function *
To restrict what gets exported:
Module manifest (.psd1):
FunctionsToExport = 'Foo', 'Bar'
Module script file (.psm1):
Export-ModuleMember -Function Foo, Bar
Note that if quotes are not used in this specific way, it will not work, and no error will be reported.
Upvotes: 0
Reputation: 109
for me, the following ( based on Mica's answer) worked:
(with the '-Force' flag: "This parameter causes a module to be loaded, or reloaded, over top of the current one." as said at https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module?view=powershell-7.1#examples)
Upvotes: 0
Reputation: 149
Ok so after a few hours I found the answer : ExportedCommand empty custom module PowerShell
You need to put RootModule = 'MyModule.psm1'
into the manifest.
Have a nice day !
Upvotes: 4