tags:

views:

69

answers:

1

Hi everybody, I try to start a function of an script out of another script. I want to save the return into a variable but this doesn't work.

script1.ps1:

function test
{
  return "hallo"
}

script2.ps1:

./script1.ps1; $p=test

or
$p = ./script1.ps1; test

It seems that $p is null, but I don't know what's wrong. Can anybody please help me? thx

+3  A: 

Try this:

. ./script1.ps1; $p=test

Why: you have to load the function into current scope (that's the period at the beginning – the dot source operator).

If you use ';', then completely new statement begins. So from you example $p = ./script.ps1; test, you assign output from script.ps1 to $p and then run the function.

stej
@stej: that's not a comma, <- that is; It's a period. <- like that ;-)
x0n
thx now it works perfekt
lepi
@x0n, of course. Thx for correction ;)
stej