|
Re: Include another script, keep variables in included script? You can export the variables to tmp2's scope:
-< tmp.ps1 >-
param ([string[]]$exportVariable)
$Test = "Here"
$There = "There"
echo "TEST: $test"
echo "There: $there"
if ($exportVariable) {
foreach ($var in $exportVariable) {
set-variable $var (get-variable $var).value -scope 1
}
}
-< tmp.ps1 >-
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
-< tmp2.ps1 >-
# $test echo "TEST: $Test"
# assuming both scripts are in same Dir
$cmd = join-path (split-path $myInvocation.myCommand.path) tmp.ps1
& $cmd -ex test, there
echo "TEST: $Test"
echo "There: $there"
-< tmp2.ps1 >-
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
.\tmp2
--
Kiron |