0

How do I use a variable in a module called from another script?

I've looked a long while for examples before asking this simple question. Every example I've found, including Microsoft's documentation only shows how to make a module and manifest and never an implementation. Because of this, I am unable to determine if I am just calling the variable wrong OR if I am unable to make an object reference in a module.

My functions are being called so the imports/exports are working as expected, and I am using a manifest to do so.

#
# Format-BLAH.psm1
#

$MyVar = New-Object MyClass($param)

# Functions declared below.
0

1 Answer 1

1

You have to manually export variables:

Export-ModuleMember -Variable MyVar
Sign up to request clarification or add additional context in comments.

4 Comments

My manifest doesn't do this for me?
@user3812871 no, in fact there's a better answer on the site already that explains the combination of the Manifest and Export-ModuleMember; will vote to close as dup.
I'm confused, what is the purpose of "FunctionsToExport = '*'" In the manifest?
@user3812871 It can actually be used to further limit what is exported by Export-ModuleMember

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.