PowerShell: How to source a function like source a file?

Question:

In my main script, I will first call an init function to initiate many variables which I expected to be used in the script. One way is to use variables whose name are like $script:var1 which are script level variable. But that’s kind of ugly and I’d like to use normal variable name, so I need a mechanism to source a function just like source a file.

When source a file, all the variables in that file are available in the calling script.

Answer:

Use the same syntax that uses dot-operator, just like for sourcing files:

Source:

PowerShell: How to source a function like source a file? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply