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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents