Must variable be global for Export-ModuleMember -Variable?

As documented in the documentation that only works in modules.

That would be the equivalent option for scripts. If you want to make a variable available outside the scope of a regular script you can declare them ‘GLOBAL:’. This way they are available for scripts or functions running in this console session.

I’d recommand not to mess with variable scopes at all and provide values for scripts or functions explicitly as parameters.

You may elaborate a little more detailed what problem you try to solve. There might be a better way. :wink: