Exporting a Variable from a Module
suggest change$FirstName = 'Bob'
Export-ModuleMember -Variable FirstName
To export a variable from a module, use Export-ModuleMember -Variable. If the manifest sets VariablesToExport and the name is not in that list, the caller does not see the variable. The manifest is the gatekeeper: a name left out of VariablesToExport or FunctionsToExport is not visible, even if Export-ModuleMember lists it.
Note: Exporting a variable is similar to making a field in a class public. It is not advisable. It would be better to expose a function to get the field and a function to set the field.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents