Exporting a Variable from a Module

suggest change
$FirstName = 'Bob'
Export-ModuleMember -Variable FirstName

To export a variable from a module, you use the Export-ModuleMember command, with the -Variable parameter. Remember, however, that if the variable is also not explicitly exported in the module manifest (.psd1) file, then the variable will not be visible to the module consumer. Think of the module manifest like a “gatekeeper.” If a function or variable isn’t allowed in the module manifest, it won’t be visible to the module consumer.

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:


PowerShell modules:
* Exporting a Variable from a Module

Table Of Contents
1 Loops
19 XML
22 Strings
25 Aliases
47 MongoDB
58 PowerShell modules
65 AWS S3