Load variables from another powershell script

By : Greg
Source: Stackoverflow.com

I have several scripts that could be reusing variables so I'd like to isolate variables in their own Variables.ps1 script, i.e.

$var1 = "1"
$var2 = "2"

I'm trying to load these variables then print them out in the Main.ps1 script like this:


This works if I first run .\Variables.ps1 but not if I just run Main.ps1. My environment is PowerShell ISE. What am I doing wrong?

By : Greg


Just to ensure correctness ... try this... in main.ps1

echo "Test"
. .\Variables.ps1
echo $var1
echo $var2

This video can help you solving your question :)
By: admin