Variables I listed to export in my powershell module manifest aren't actually exporting Variables I listed to export in my powershell module manifest aren't actually exporting powershell powershell

Variables I listed to export in my powershell module manifest aren't actually exporting


So for the sake of completeness and for anybody that lands on this question in the future I am going to sum up the conversation we had in the comments to the OP's question.

All functions are exported from a module by default, no other members exhibit this behavior. It is as if Export-ModuleMember -Function * is implicitly called from within the module. You can then further restrict what functions are exported via the ExportedFunctions key in the module manifest, e.g. ExportedFunctions : {Get-WidgetBlessing, Get-WidgetName}.

If you want to export variables or aliases you have to explicitly add a call to Export-ModuleMember -Variable <what you want to export> or Export-ModuleMember -Alias <what you want to export> in your module. However, once you have added an explicit call to Export-ModuleMember the implicit call to Export-ModuleMember -Function * no longer happens. You have to remember to add Export-ModuleMember -Function * to your module explicitly if you add even one other explicit call to Export-ModuleMember or else your functions will no longer continue to be exported.


Actually noticed the valid response is opposite to documentation.

From Microsoft

FunctionsToExport

Specifies the functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. By default, no functions are exported. You can use this key to list the functions that are exported by the module. The module exports the functions to the caller's session state. The caller's session state can be the global session state or, for nested modules, the session state of another module. When chaining nested modules, all functions that are exported by a nested module will be exported to the global session state unless a module in the chain restricts the function by using the FunctionsToExport key. If the manifest exports aliases for the functions, this key can remove functions whose aliases are listed in the AliasesToExport key, but this key cannot add function aliases to the list. Example: FunctionsToExport = @("function1", "function2", "function3")

VariablesToExport

Specifies the variables that the module exports to the caller's session state. Wildcard characters are permitted. By default, all variables ('*') are exported. You can use this key to restrict the variables that are exported by the module. The caller's session state can be the global session state or, for nested modules, the session state of another module. When you are chaining nested modules, all variables that are exported by a nested module will be exported to the global session state unless a module in the chain restricts the variable by using the VariablesToExport key. If the manifest also exports aliases for the variables, this key can remove variables whose aliases are listed in the AliasesToExport key, but this key cannot add variable aliases to the list. Example: VariablesToExport = @('$MyVariable1', '$MyVariable2', '$MyVariable3')