Calling Variables from another file

by Sep 24, 2014

What I am trying to do is:

 

1) Create a central file that contains multiple variables like this.

 

                $report = "/home/report"

                $report 2 = "/home/report2"

                $user 1= bob

                $user 2= tim

 

 

2) Call and use those variables in PS Scripts from the central variable file.

 

Script 1 hard coding Variables: Compare-Object -ReferenceObject /home/report -DifferenceObject /home/report2

 

Script 1 calling Variables from central file: Compare-Object -ReferenceObject $report -DifferenceObject $report2

 

 

Script 2 hard coding Variables:  Get-Content -Path $report -Exclude bob -Include tim

 

Script 2 calling Variables from central file:  Get-Content -Path $report -Exclude $user 1 -Include $user 2

 

 

Script 3 hard coding Variables:  Get-Content -Path /home/report2 -Exclude tim

 

Script 3 calling Variables from central file:  Get-Content -Path $report2 -Exclude $user 2

 

 

 

My whole intent is to be able to set the variables in one location and use them in any script I have without having to set them every time. Also If they need to change I just change one file instead for 15 different one.

 

Does anyone know how I would go about doing this?